Skip to content

GH-10058: Add Jackson 3 ObjectMapper and MessageParser #10160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

anthologia
Copy link
Contributor

@anthologia anthologia commented Jun 23, 2025

Related to: #10058

  • Add Jackson3JsonObjectMapper, Jackson3JsonMessageParser to prepare for Jackson 2 to 3 migration (Work3).

Jackson 3 Exception Model Changes

Jackson 3 changed its exception hierarchy from checked to unchecked.

Now, JacksonException extends RuntimeException not IOException.

Jackson 3 default setting changes

Jackson 3.0 has different default settings compared to 2.x that may affect serialization behavior.

For example, these timestamp-related settings have changed:

  • WRITE_DATES_AS_TIMESTAMPS(false) // was true in 2.x
  • WRITE_DURATIONS_AS_TIMESTAMPS(false) // was true in 2.x
  • ONE_BASED_MONTHS(true) // was false in 2.x

Should we maintain Jackson 2.x compatibility, or adopt Jackson 3 defaults?

Related to: spring-projects#10058

* Add Jackson3JsonObjectMapper, Jackson3JsonMessageParser to prepare for Jackson 2 to 3 migration.

Signed-off-by: Jooyoung Pyoung <[email protected]>
Map<String, Object> headers = null;
Object payload = null;
while (JsonToken.END_OBJECT != parser.nextToken()) {
Assert.isTrue(JsonToken.PROPERTY_NAME == parser.currentToken(), error);
Copy link
Contributor Author

@anthologia anthologia Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!
This is great start!
Any chances to have some tests on the matter?
Especially I'm interested in those loaded by the Jackson 3 modules if we remove our custom collectWellKnownModulesIfAvailable().

Re. defaults in v3 VS v2: I have raised concern with the team.
Will come back to ASAP.

* @since 7.0
*/
public class Jackson3JsonMessageParser extends AbstractJacksonJsonMessageParser<JsonParser> {
private static final JsonFactory JSON_FACTORY = JsonFactory.builder().build();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every member in the class has to be surrounded with blank lines.

List<JacksonModule> jacksonModules = collectWellKnownModulesIfAvailable();
this.objectMapper = JsonMapper.builder()
.addModules(jacksonModules)
.build();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see Spring Framework does this instead:

 JsonMapper.builder().findAndAddModules(Jackson3JsonObjectMapper.class.getClassLoader()).build();

Maybe we check if really those well-known modules are picked up properly by Jackson 3 native API?
I mean this our new class might be a bit lighter without those inner classes and collectWellKnownModulesIfAvailable() ?

}

@Override
protected JsonParser createJsonParser(String jsonMessage) throws JacksonException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You said this JacksonException is an unchecked exception, so no need to mention it here I believe.

}

@Override
public String toJson(Object value) throws JacksonException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think to support this abstraction contract we have to re-throw an IOException instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants