-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
base: main
Are you sure you want to change the base?
Conversation
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this 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(); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
Related to: #10058
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
extendsRuntimeException
notIOException
.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.xWRITE_DURATIONS_AS_TIMESTAMPS(false)
// was true in 2.xONE_BASED_MONTHS(true)
// was false in 2.xShould we maintain Jackson 2.x compatibility, or adopt Jackson 3 defaults?