ClassCastException on deserialization of spring jms GenericMessage
See original GitHub issueHi there,
I already put some effort in debugging the following exception:
Caused by: java.lang.ClassCastException: org.springframework.messaging.support.GenericMessage cannot be cast to com.fasterxml.jackson.databind.JsonNode
at com.fasterxml.jackson.databind.deser.std.StdNodeBasedDeserializer.deserializeWithType(StdNodeBasedDeserializer.java:84)
at com.fasterxml.jackson.databind.deser.impl.TypeWrappedDeserializer.deserialize(TypeWrappedDeserializer.java:68)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4013)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3042)
at org.springframework.jms.support.converter.MappingJackson2MessageConverter.convertFromTextMessage(MappingJackson2MessageConverter.java:385)
at org.springframework.jms.support.converter.MappingJackson2MessageConverter.convertToObject(MappingJackson2MessageConverter.java:363)
at org.springframework.jms.support.converter.MappingJackson2MessageConverter.fromMessage(MappingJackson2MessageConverter.java:232)
at org.springframework.jms.core.JmsTemplate.doConvertFromMessage(JmsTemplate.java:859)
at org.springframework.jms.core.JmsTemplate.receiveAndConvert(JmsTemplate.java:817)
at org.springframework.integration.jms.PollableJmsChannel.receive(PollableJmsChannel.java:110)
at org.springframework.integration.jms.PollableJmsChannel.receive(PollableJmsChannel.java:83)
at org.springframework.integration.endpoint.PollingConsumer.receiveMessage(PollingConsumer.java:203)
at org.springframework.integration.endpoint.AbstractPollingEndpoint.doPoll(AbstractPollingEndpoint.java:360)
at org.springframework.integration.endpoint.AbstractPollingEndpoint.pollForMessage(AbstractPollingEndpoint.java:329)
... 14 more
Context: I am using spring integration with a JMS queue. I can see the message correctly been written to the database and interestingly the data is also correctly deserialized until https://github.com/FasterXML/jackson-databind/blob/master/src/main/java/com/fasterxml/jackson/databind/deser/std/StdNodeBasedDeserializer.java#L77 where it results in the classCastException shown above.
I am using the following mapper configuration:
@Bean
public MessageConverter jacksonJmsMessageConverter() {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
converter.setTargetType(MessageType.TEXT);
converter.setTypeIdPropertyName("_type");
ObjectMapper objectMapper = JacksonJsonUtils.messagingAwareMapper("com.github.maybeec");
// objectMapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE);
converter.setObjectMapper(objectMapper);
return converter;
}
@Bean(name = JMSEmailNotificationConsumer.EMAIL_QUEUE)
public MessageChannel emailQueue(QueueConnectionFactory jmsConnectionFactory) {
return Jms.pollableChannel(JMSEmailNotificationConsumer.EMAIL_QUEUE, jmsConnectionFactory)
.datatype(JMSEmailTo.class).messageConverter(jacksonMessageConverter())
.jmsMessageConverter(jacksonJmsMessageConverter()).datatype(JMSEmailTo.class).deliveryPersistent(true)
.destination(JMSEmailNotificationConsumer.EMAIL_QUEUE).get();
}
@Bean
public JmsTemplate jmsTemplate(QueueConnectionFactory jmsConnectionFactory) throws Exception {
JmsTemplate jmsTemplate = new JmsTemplate();
jmsTemplate.setConnectionFactory(jmsConnectionFactory);
jmsTemplate.setMessageConverter(jacksonJmsMessageConverter());
jmsTemplate.setPubSubDomain(false);
jmsTemplate.setDeliveryPersistent(true);
return jmsTemplate;
}
Product Versions: I am using Spring Integration 5.1.6.RELEASE with the managed version of spring of jackson-databind: 2.9.9.
Trials so far:
- I tried upgrading to the latest jackson-databind 2.10.1, which did not made any difference
- I tried enabling
UNWRAP_ROOT_VALUE
feature without any success. In that case I got
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Root name '@class' does not match expected ('GenericMessage') for type [simple type, class org.springframework.messaging.support.GenericMessage]
at [Source: (String)"{"@class":"org.springframework.messaging.support.GenericMessage","payload":{"@class":"com.kn.fn.fia.emailadapter.logic.impl.jmsadapter.to.JMSEmailTo","from":"malte.brunnlieb@capgemini.com","to":"malte.brunnlieb@capgemini.com","cc":"malte.brunnlieb@capgemini.com","bcc":null,"replyTo":"malte.brunnlieb@capgemini.com","sentDate":"Thu Nov 21 22:34:58 CET 2019","subject":" Quote 111 from SINGAPORE to tokyo \r\n","text":"<!DOCTYPE html> \r\n <html> \r\n <head> \r\n <sty"[truncated 6974 chars]; line: 1, column: 2]
at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59)
at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1356)
at com.fasterxml.jackson.databind.ObjectMapper._unwrapAndDeserialize(ObjectMapper.java:4087)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4011)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3042)
at org.springframework.jms.support.converter.MappingJackson2MessageConverter.convertFromTextMessage(MappingJackson2MessageConverter.java:385)
at org.springframework.jms.support.converter.MappingJackson2MessageConverter.convertToObject(MappingJackson2MessageConverter.java:363)
at org.springframework.jms.support.converter.MappingJackson2MessageConverter.fromMessage(MappingJackson2MessageConverter.java:232)
... 21 more
which is also not clear to me why the simple type is being compared with the full qualified type.
Any ideas?
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Cannot convert object of type to JMS message. Supported ...
Now ClassCastException exception says: sending and receiving part are mutual not compatible. Framework or server made conversion ...
Read more >ClassCastException using same jar file - JBoss.org
Hi, we are developing out project from 3 different eclipse projects. One is utils project which expose common.jar file.
Read more >Spring Integration Reference Guide
Mapping Message Headers to and from JMS Message . ... The base implementation of the Message interface is GenericMessage<T>, and it provides two....
Read more >spring-projects/spring-amqp - Gitter
LogEvent] for GenericMessage ... withBody(SerializationUtils.serialize(logEvent)) . ... PingMessage] for org.springframework.jms.listener.adapter.
Read more >Explanation of ClassCastException in Java - Baeldung
Let's take a closer look at the ClassCastException. ... Get started with Spring 5 and Spring Boot 2, through the Learn Spring course:....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah I am not going to do that: I see nothing to really suggest specific problem in Jackson. What is needed is piece of code isolate out of Spring; without this my time is better spent with other issues.
这个问题我也遇到了,加个参数就行了