Results 1 to 5 of 5

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

  1. #1
    Join Date
    Nov 2007
    Posts
    177

    Default "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. #2
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    646

    Default

    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

  3. #3
    Join Date
    Nov 2007
    Posts
    177

    Default

    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.

  4. #4
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,040

    Default

    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>
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  5. #5
    Join Date
    Nov 2007
    Posts
    177

    Default

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •