Announcement Announcement Module
Collapse
No announcement yet.
"MessageConversionException: failed to convert Message content" with JSon Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • "MessageConversionException: failed to convert Message content" with JSon

    Hello,

    I am trying to convert an amqp message from JSon to java and I get the following cryptic error:

    Code:
    Exception in thread "main" org.springframework.amqp.support.converter.MessageConversionException: failed to convert Message content. Could not resolve
     __TypeId__ in header
    	at org.springframework.amqp.support.converter.DefaultJavaTypeMapper.retrieveHeader(DefaultJavaTypeMapper.java:104)
    	at org.springframework.amqp.support.converter.DefaultJavaTypeMapper.toJavaType(DefaultJavaTypeMapper.java:53)
    	at org.springframework.amqp.support.converter.JsonMessageConverter.fromMessage(JsonMessageConverter.java:118)
    	at org.springframework.amqp.rabbit.core.RabbitTemplate.receiveAndConvert(RabbitTemplate.java:425)
    	at trc.suivi.amqp.Consumer.main(Consumer.java:12)
    Here is my Spring config:

    Code:
    	<rabbit:connection-factory id="connectionFactory" />
    	<rabbit:template id="amqpTemplate" connection-factory="connectionFactory" message-converter="messageConverter"/>
    	<rabbit:admin connection-factory="connectionFactory" />
    	<rabbit:queue name="myqueue" />
    
    	<bean id="messageConverter" class="org.springframework.amqp.support.converter.JsonMessageConverter" />
    Can anyone please help?

    Regards,

    Julien.

  • #2
    Hi, Julien!

    As you see by StackTrace it asks you to have a specific header in the incoming Message - __TypeId__
    And of course documentation here: http://static.springsource.org/sprin...single/#d4e288

    HTH

    Take care,
    Artem

    Comment


    • #3
      Hi Artem,
      Do you have any idea what information this header ( __TypeId__) conveys?
      I was not able to find any info on the web about it or about what to set it to...
      J.

      Comment


      • #4
        The JsonMessageConverter (by default) uses message properties (headers) to determine the type information - what type do you want to create from the JSON.

        This is set up properly if spring-amqp created the message (using a JsonMessageConverter on the outbound).

        If something else is creating the message, there will be no type information and the converter won't be able to convert.

        This mechanism can be overridden using a custom ClassMapper implementation.

        In 1.1.3 we added the capability to configure a type into the DefaultClassMapper...

        Code:
        	<bean id="jsonOrderConverter" class="org.springframework.amqp.support.converter.JsonMessageConverter">
        		<property name="classMapper">
        			<bean class="org.springframework.amqp.support.converter.DefaultClassMapper">
        				<property name="defaultType" value="foo.MyObject" />
        			</bean>
        		</property>
        	</bean>

        Comment


        • #5
          Gary,
          Thanks a lot. It works fine with the classMapper property.
          Regards,
          J.

          Comment

          Working...
          X