-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Allow JSON serialization customization in ORM #35113
Allow JSON serialization customization in ORM #35113
Conversation
5d3e509
to
add9361
Compare
This comment has been minimized.
This comment has been minimized.
add9361
to
7762919
Compare
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.
This looks good, but I wonder why we're going through a configuration property when we could just use CDI? I.e. like we do for interceptors.
Also I'd advise against configuration properties that refer to class names, that'll put us in a difficult position if we ever end up allowing to point to a CDI bean through configuration properties. Hibernate Search supports that, but it requires some infrastructure that I'm not sure ORM provides at the moment (see https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#configuration-bean-reference-parsing).
IDK 🤷🏻 🤷🏻♂️ 🤷🏻♀️ 😆 I'm probably just more used to config properties than to configuring things through beans 😃. So if we'd go with CDI.. then it would looks something like: InjectableInstance<FormatMapper> formatMapper = PersistenceUnitUtil.singleExtensionInstanceForPersistenceUnit(
FormatMapper.class, persistenceUnitName);
if (!formatMapper.isUnsatisfied()) {
descriptor.getProperties().put(AvailableSettings.JSON_FORMAT_MAPPER, formatMapper.get());
} and then the user would do: @PersistenceUnitExtension("some-pu")
public class SomePuFormatMapper implements FormatMapper {
// ...
} But since this |
This comment has been minimized.
This comment has been minimized.
+1 for this - it also makes for a consistent user experience
Very very true |
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 added a comment below about something I didn't spot earlier.
But since this FormatMapper is used for both JSON and XML formatters in ORM... should we create JsonFormatMapper and XmlFormatMapper and expect users to implement these so we'd know to which property to attach the formatter to?
FormatMapper
is an ORM interface, so I wouldn't extend it.
You may be able to introduce additional CDI qualifiers, such as @Json
and @Xml
, and pick the mapper based on that? And default to an object mapper without any of these qualifiers.
I wonder if there is already something like this for e.g. RestEasy, @geoand? I'd rather have these qualifiers defined in some serialization-related module than in the Hibernate ORM extension, if possible...
BTW, we should probably go ahead and add the same thing for XML while we are at it, no?
Probably, if it works, including in native mode.
...orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/FastBootMetadataBuilder.java
Outdated
Show resolved
Hide resolved
We don't have such qualifiers anywhere AFAIK.
We had talked about for RESTEasy Reactive, but it never materialized (not least because there are other ways to do this in RESTEasy Reactive) |
Ok, so now might be the time. There's no obvious place to put these annotations in, though... I can think of two approaches:
I'd tend to favor 2 since there doesn't seem to be much momentum to add similar annotations for RestEasy. WDYT? |
I agree with going for |
I'd also prefet option 2, as it might not be a good idea to dictate a format that necessarily applies to multiple layers: there might be some need to map the same object differently in the DB than in other external representations, as one would typically update one service at a time. |
Sure, but having a common Anyway, let's forget about a common @marko-bekhta , to sum up the consensus seems to be that if you add support for XML |
7762919
to
2939682
Compare
This will need the next release of ORM to make |
This comment has been minimized.
This comment has been minimized.
2939682
to
120bd07
Compare
🙈 The PR is closed and the preview is expired. |
120bd07
to
b580d5f
Compare
This comment has been minimized.
This comment has been minimized.
- add qualifiers to mark FormatMapper for JSON/XML formatting - use a Quarkus-configured ObjectMapper if Jackson is present and user did not specify a format mapper - use a Quarkus-configured Jsonb if Jsonb is present and user did not specify a format mapper
b580d5f
to
47ecd0a
Compare
Rebasing and marking as ready for review since we're now using a version of ORM that exposes these two options. |
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.
LGTM, thanks.
@geoand maybe you'll want to have a look at the changes to the JSON extensions?
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.
Lovely!
Failing Jobs - Building 47ecd0a
You can also consult the Develocity build scans. Failures⚙️ JVM Tests - JDK 21 #- Failing: integration-tests/container-image/maven-invoker-way
📦 integration-tests/container-image/maven-invoker-way✖ |
Build failure is unrelated:
|
@marko-bekhta Merged, thanks! |
@JsonFormat
/@XmlFormat
annotations to apply to custom FormatMapper implementations for JSON/XML formatting (must also use@PersistenceUnitExtension
)Closes: #32029