-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-19890 Add Jackson 3 FormatMapper support #11357
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?
HHH-19890 Add Jackson 3 FormatMapper support #11357
Conversation
| * @author Christian Beikov | ||
| * @author Yanming Zhou | ||
| * @author Nick Rayburn | ||
| */ |
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.
Not sure if the previous author's need to be retained. This file was copied from the existing one that they were on. (I also don't need my name in here either unless it's the project standard, just tried to match what I copied from.)
hibernate-core/src/main/java/org/hibernate/type/format/jackson/Jackson3XmlFormatMapper.java
Outdated
Show resolved
Hide resolved
|
You should take care of backward compatibility. Jackson 3 does not have JSR 310 module since it is handling Here is one example that is showing the problem |
caa4ff0 to
b85e057
Compare
|
Thanks @cigaly, I added the tests and updated the implementation to pass. Are you suggesting that the new Jackson 3 support should match the existing Jackson 2 support as closely as possible or are you only concerned about the Jackson 3 changed default options for some features, so the new code here would just need to configure those back to the Jackson 2 values. I don't think there's a problem with this, but I wanted to check before I make that change. |
b85e057 to
f2a08e9
Compare
|
Main point is that one should be careful with backward compatibility. If I have project that was using Hibernate + Jackson 2, then I would expect that it will work with Jackson 3 as well without some major code changes. I am not 100% sure how many incompatibilities are introduced when switching from Jackson 2 to 3, One good thing with |
|
I think it’s a reasonable concern. Even if Jackson can serialize/deserialize the data if it isn’t the same format, there could still be other impact if the data being stored in the database is changed.
Not sure if any of that changes your opinion on how much we configure the Jackson 3 support to align with the existing Jackson 2 support. I can review the relevant Jackson features, but I think it will be 10+ that need to be explicitly configured to old defaults to be safe. |
|
Jackson offers a method that configures the mapper to use the Jackson 2 settings. I’ll adjust the PR to use that. This will resolve most of the concerns, but it’s probably still worth considering if Jackson 3 is part of the automatic detection or not. |
f2a08e9 to
fd2673f
Compare
|
Updated the code to use the Jackson methods to use the Jackson 2 defaults. I found a few discrepancies and opened PRs against Jackson to resolve those. |
hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java
Outdated
Show resolved
Hide resolved
hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java
Outdated
Show resolved
Hide resolved
hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/JsonJavaTimeMappingTests.java
Outdated
Show resolved
Hide resolved
fd2673f to
9a8f647
Compare
This comment was marked as resolved.
This comment was marked as resolved.
9a8f647 to
f57b428
Compare
| strategySelector.registerStrategyImplementor( | ||
| FormatMapper.class, | ||
| Jackson3JsonFormatMapper.SHORT_NAME, | ||
| Jackson3JsonFormatMapper.class | ||
| ); |
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation
| strategySelector.registerStrategyImplementor( | ||
| FormatMapper.class, | ||
| Jackson3XmlFormatMapper.SHORT_NAME, | ||
| Jackson3XmlFormatMapper.class | ||
| ); |
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation
| (session) -> { | ||
| // PostgreSQL returns the JSON slightly formatted | ||
| String alternativePostgreSQLJson = | ||
| "{\"instant\": 1764576582.000000000, \"duration\": 11640.000000000, \"localDate\": [2025, 12, 1], \"localTime\": [9, 9, 42], \"localDateTime\": [2025, 12, 1, 9, 9, 42]}"; |
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.
Looks like MySQL adds some spaces to the JSON that we have to account for.
| "{\"instant\": 1764576582.000000000, \"duration\": 11640.000000000, \"localDate\": [2025, 12, 1], \"localTime\": [9, 9, 42], \"localDateTime\": [2025, 12, 1, 9, 9, 42]}"; | |
| "{\"instant\": 1764576582.000000000, \"duration\": 11640.000000000, \"localDate\": [2025, 12, 1], \"localTime\": [9, 9, 42], \"localDateTime\": [2025, 12, 1, 9, 9, 42]}"; | |
| String alternativeMySQLJson = | |
| "{\"instant\": 1764576582.000000000, \"localDateTime\": [2025, 12, 1, 9, 9, 42], \"localDate\": [2025, 12, 1], \"localTime\": [9, 9, 42], \"duration\": 11640.000000000}"; |
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.
Is there an easy way for me to test this locally?
I updated the test with a MySQL version and a MariaDB version based on what I'm seeing as failed in CI.
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.
Ughh, this start to get ugly. Can you try parsing the JSON with the format mapper to e.g. a Map and do the comparison that way?
See the README which explains how to start and run against databases locally ;)
f57b428 to
8658741
Compare
This adds Jackson 3 support alongside the existing Jackson 2 support.
./gradlew clean build.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.
https://hibernate.atlassian.net/browse/HHH-19890