I am upgrading a project from Spring Boot 3.5 to Spring Boot 4. As part of the change, I changed configuring the MappingJackson2MessageConverter (which uses Jackson 2) to use JacksonJsonMessageConverter (which uses Jackson 3). I had some test failures after that in tests that check what happens if an invalid JMS message is put on the queue.
After some investigation, I noticed the following. This is the method body:
@Override
public Object fromMessage(Message message) throws JMSException, MessageConversionException {
try {
JavaType targetJavaType = getJavaTypeForMessage(message);
return convertToObject(message, targetJavaType);
}
catch (IOException ex) {
throw new MessageConversionException("Failed to convert JSON message content", ex);
}
}
Notice the catch(IOException). In Jackson 2, all exceptions thrown by Jackson are subclasses of IOException. So if the conversion cannot be done, the catch clause converts this to a MessageConversionException. This is also what my code expected to work properly.
With JacksonJsonMessageConverter, the code is still the same, but now Jackson 3 does not throw an IOException anymore. It now uses tools.jackson.core.JacksonException which is a RuntimeException.
As a result, there is no MessageConversionException anymore.
I can fix it on my side by catching JacksonException, as well as MessageConversionException, but I think it would be better if a catch for JacksonException is added that converts it to a MessageConversionException so the behaviour is the same as it was before.
I am upgrading a project from Spring Boot 3.5 to Spring Boot 4. As part of the change, I changed configuring the
MappingJackson2MessageConverter(which uses Jackson 2) to useJacksonJsonMessageConverter(which uses Jackson 3). I had some test failures after that in tests that check what happens if an invalid JMS message is put on the queue.After some investigation, I noticed the following. This is the method body:
Notice the
catch(IOException). In Jackson 2, all exceptions thrown by Jackson are subclasses of IOException. So if the conversion cannot be done, the catch clause converts this to aMessageConversionException. This is also what my code expected to work properly.With
JacksonJsonMessageConverter, the code is still the same, but now Jackson 3 does not throw an IOException anymore. It now usestools.jackson.core.JacksonExceptionwhich is aRuntimeException.As a result, there is no
MessageConversionExceptionanymore.I can fix it on my side by catching
JacksonException, as well asMessageConversionException, but I think it would be better if a catch forJacksonExceptionis added that converts it to aMessageConversionExceptionso the behaviour is the same as it was before.