spring-projects / spring-projects/spring-framework

Error handling in JacksonJsonMessageConverter different from MappingJackson2MessageConverter

Open
#36,424 0 comments 1 reaction 1 assignee View on GitHub

@sdeleuze is already working on this.

Since Mar 6, 2026.

in: web status: waiting-for-triage
Dominant language
Java
Stars
60.2k
Forks
38.8k
Avg merge
5d 2h
Merged PRs (30d)
27

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.