-
Notifications
You must be signed in to change notification settings - Fork 3k
Remove "default" formatter mappers and let ORM build them itself #48177
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
Remove "default" formatter mappers and let ORM build them itself #48177
Conversation
/cc @gsmet (hibernate-orm) |
also pinging @yrodiere and @lucamolteni 🙂 |
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.
IIUC custom formats are still supported through CDI and @JsonFormat
etc., we just don't use the (generally REST-oriented) objectmappers/formatters by default, and instead rely on ORM's?
This seems reasonable to me.
I have two concerns:
- Regarding migration, do you think there is any way that switching from the default
ObjectMapper
(or similar) to the one built by Hibernate ORM could lead to silent data loss? Errors are fine (ish) if there's a migration path, but silently dropping data would be a huge problem. - Do we have native tests for these features? Because depending when Hibernate ORM builds the "default formatters", the reflection involved could lead to quite a few problems.
yes 👍🏻
well the ORM's one is a pretty straightforward config (e.g. So my thinking here is that for the migration guide, we suggest this: @Inject
public OrmJsonFormatMapper(ObjectMapper objectMapper) {
this.mapper = new JacksonJsonFormatMapper(objectMapper);
} so that the app keeps doing what it was doing, (inject the Quarkus' object mapper (or Jsonb or anything else) into this formatter to get them up and running and as a second step we'd suggest that they get rid of the injection and create a clean mapper + configure it the way they need it for the DB operations + do any data migration as necessary. now ... yes, if someone misses this in the migration guide... I suppose we could try creating these beans from our side if user haven't provided their custom one (that's actually somewhat where we are right now), and log some warnings telling them "hey this will break in the next version, you should change it", and then actually make it fail in the next one? But then we'd force everyone to create some format mappers... IDK that would be safer (for data) but more annoying for the users..
yes, in the Postgresql module ... here's one for the "custom formatter": Lines 23 to 24 in 47ecd0a
and then the one using the defaults: Lines 22 to 23 in 47ecd0a
|
I'd say the focus here should be on detecting problematic cases with zero false negatives and as few false positives as possible. From what I understand, there can be a problem if all of the following are true:
If we can detect all that, I think we're in a pretty narrow case, and it would be fine to warn, then error out in a future version, like you mentioned. Maybe put this behavior behind a setting ( @gsmet would that make sense? |
983fc6a
to
f27237e
Compare
...ate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmConfig.java
Outdated
Show resolved
Hide resolved
.../src/main/java/io/quarkus/hibernate/orm/runtime/customized/BuiltinFormatMapperBehaviour.java
Outdated
Show resolved
Hide resolved
.../src/main/java/io/quarkus/hibernate/orm/runtime/customized/BuiltinFormatMapperBehaviour.java
Outdated
Show resolved
Hide resolved
402cbe8
to
393874e
Compare
🎊 PR Preview 3e365d6 has been successfully built and deployed to https://quarkus-pr-main-48177-preview.surge.sh/version/main/guides/
|
.../src/main/java/io/quarkus/hibernate/orm/runtime/customized/BuiltinFormatMapperBehaviour.java
Outdated
Show resolved
Hide resolved
.../src/main/java/io/quarkus/hibernate/orm/runtime/customized/BuiltinFormatMapperBehaviour.java
Outdated
Show resolved
Hide resolved
...ate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmConfig.java
Outdated
Show resolved
Hide resolved
c33cb99
to
4d3dca5
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
...ate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmConfig.java
Outdated
Show resolved
Hide resolved
LGTM. Let's merge once you've removed the deprecation? Also, could you please set a reminder for yourself to switch the default to |
4d3dca5
to
a83d2ae
Compare
done 👍🏻 😃 |
This comment has been minimized.
This comment has been minimized.
Alright, thanks. Then let's merge after the build succeeds. |
a83d2ae
to
2f7b184
Compare
Status for workflow
|
Status for workflow
|
fixes #47588 (in a way 😄)
ObjectMapper
in a specific way if the Oracle DB is in use. This will probably be part of 7.1 or so, and once it's out, we'd need to adapt and "copy" that logic hereso with that ^ let's just drop the "default" mappers and let Hibernate ORM do its thing and configure it in a way it wants by default. If users want more control over it they could (and should) use the
@io.quarkus.hibernate.orm.JsonFormat
+@io.quarkus.hibernate.orm.PersistenceUnitExtension
: https://quarkus.io/guides/hibernate-orm#json_xml_serialization_deserializationAs this is a breaking change ... for migration purposes... we'd suggest that users define a
FormatMapper
like:to get the same behaviour as right now, and hint them to reconsider using the injected object mapper, but built one themselves for persistence purposes ?
I'm opening this as a draft to discuss this approach. If we agree on it, I will prepare and test examples for each mapper type and write the migration note. 😃