Skip to content
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

Jakarta - EE 10 - Weird Jackson serialization issue in REST Data Panache #28016

Closed
gsmet opened this issue Sep 16, 2022 · 9 comments · Fixed by #28076
Closed

Jakarta - EE 10 - Weird Jackson serialization issue in REST Data Panache #28016

gsmet opened this issue Sep 16, 2022 · 9 comments · Fixed by #28076
Assignees
Labels
area/jackson Issues related to Jackson (JSON library) area/jakarta area/panache
Milestone

Comments

@gsmet
Copy link
Member

gsmet commented Sep 16, 2022

The extensions/panache/hibernate-orm-rest-data-panache/deployment tests in jakarta-rewrite has started to fail (not every time AFAICS) with stackoverflow errors:

Infinite recursion (StackOverflowError) (through reference chain: io.quarkus.hibernate.orm.rest.data.panache.deployment.entity.Collection["items"]->org.hibernate.collection.internal.PersistentBag[0]->io.quarkus.hibernate.orm.rest.data.panache.deployment.entity.Item["collection"]->io.quarkus.hibernate.orm.rest.data.panache.deployment.entity.Collection["items"]->org.hibernate.collection.internal.PersistentBag[0]->io.quarkus.hibernate.orm.rest.data.panache.deployment.entity.Item["collection"]->io.quarkus.hibernate.orm.rest.data.panache.deployment.entity.Collection["items"]->org.hibernate.collection.internal.PersistentBag[0]->io.quarkus.hibernate.orm.rest.data.panache.deployment.entity.Item["collection"]->io.quarkus.hibernate.orm.rest.data.panache.deployment.entity.Collection["items"]->org.hibernate.collection.internal.PersistentBag[0]->io.quarkus.hibernate.orm.rest.data.panache.deployment.entity.Item["collection"]->io.quarkus.hibernate.orm.rest.data.panache.deployment.entity.Collection["items"]->org.hibernate.collection.internal.PersistentBag[0]->io.quarkus.hibernate.orm.rest.data.panache.deployment.entity.Item["collection"]->io.quarkus.hibernate.orm.rest.data.panache.deployment.entity.Collection["items"]->org.hibernate.collection.internal.PersistentBag[0]->io.quarkus.hibernate.orm.rest.data.panache.deployment.entity.Item["collection"]->io.quarkus.hibernate.orm.rest.data.panache.deployment.entity.Collection["items"]->org.hibernate.collection.internal.PersistentBag[0]->io.quarkus.hibernate.orm.rest.data.panache.deployment.entity.Item["collection"]->io.quarkus.hibernate.orm.rest.data.panache.deployment.entity.Collection["items"]->org.hibernate.collection.internal.PersistentBag[0]->io.quarkus.hibernate.orm.rest.data.panache.deployment.entity.Item["collection"]->io.quarkus.hibernate.orm.rest.data.panache.deployment.entity.Collection["items"]->org.hibernate.collection.internal.PersistentBag[0]->io.quarkus.hibernate.orm.rest.data.panache.deployment.entity.Item["collection"]

I always get the error in io.quarkus.hibernate.orm.rest.data.panache.deployment.entity.PanacheEntityResourcePathCustomisationTest locally. It seems the other tests are OK.
We have some Jackson annotations to prevent this issue so not sure what's going on. And also not sure what's specific to Jakarta.

What I don't understand is that it's not an issue in main Quarkus. Also once we have this error, Quarkus is in a very weird state as once I reproduce this, the build is stuck for several minutes until it's cancelled by our test infrastructure.

@quarkus-bot
Copy link

quarkus-bot bot commented Sep 16, 2022

/cc @FroMage, @geoand, @loicmathieu

@quarkus-bot quarkus-bot bot added area/jackson Issues related to Jackson (JSON library) area/panache labels Sep 16, 2022
@geoand
Copy link
Contributor

geoand commented Sep 16, 2022

cc @Sgitario

@Sgitario
Copy link
Contributor

I could find the root cause of this issue. From Jackson 2.13.4, they changed the primary annotation instrospector (the entity that inspect the annotations in use) from ParameterNamesAnnotationIntrospector to JakartaXmlBindAnnotationIntrospector (see commit here).

This was done because a new module for jakarta was added.

And the problem is that we add dynamically the @XmlTransient annotation to all the fields of an entity:

Therefore, the new behaviour in JakartaXmlBindAnnotationIntrospector makes the annotations within the field to be ignored.

@gsmet
Copy link
Member Author

gsmet commented Sep 19, 2022

I always forget that they based the JAX-RS JSON support in Jackson on the XML one...

@gsmet
Copy link
Member Author

gsmet commented Sep 19, 2022

@Sgitario are you sure it was only ParameterNamesAnnotationIntrospector before? Because I don't see it actually doing anything with the ignore annotations?

Trying to make sure I understand why the behavior change. Because I would have expected Jackson 2.13 non-jakarta to have a javax equivalent of this.

@Sgitario
Copy link
Contributor

@Sgitario are you sure it was only ParameterNamesAnnotationIntrospector before? Because I don't see it actually doing anything with the ignore annotations?

Trying to make sure I understand why the behavior change. Because I would have expected Jackson 2.13 non-jakarta to have a javax equivalent of this.

Actually, before it was working because ParameterNamesAnnotationIntrospector was ignoring the XmlTransient annotations and now JakartaXmlBindAnnotationIntrospector is taking into account it.

@gsmet
Copy link
Member Author

gsmet commented Sep 19, 2022

@Sgitario so https://github.com/FasterXML/jackson-modules-base/blob/2.13/jaxb/src/main/java/com/fasterxml/jackson/module/jaxb/JaxbAnnotationIntrospector.java is not used in the javax flavor?
What I would like to understand is how we switched from one to another, because I thought we would have JaxbAnnotationIntrospector around before.

From what I read from the Jackson commit, we need to explicitly register the module. So was the JAXB module not registered before? And now the JakartaXmlBind one is?
And how did that affect the JSON ObjectMapper we should use?

@Sgitario
Copy link
Contributor

The jackson-module-jakarta-xmlbind-annotations dependency is coming from resteasy-jackson2-provider which is used by the Resteasy Jackson extension. And having this dependency in the classpath will replace the previous setup that was defined by the Quarkus Jackson extension.

@gsmet
Copy link
Member Author

gsmet commented Sep 19, 2022

@Sgitario can you point me where it's done? Because that's not obvious to me that it should.

Sgitario added a commit to Sgitario/quarkus that referenced this issue Sep 19, 2022
Sgitario added a commit to Sgitario/quarkus that referenced this issue Sep 19, 2022
Sgitario added a commit to Sgitario/quarkus that referenced this issue Sep 20, 2022
Sgitario added a commit to Sgitario/quarkus that referenced this issue Sep 20, 2022
@quarkus-bot quarkus-bot bot added this to the 2.14 - main milestone Sep 20, 2022
igorregis pushed a commit to igorregis/quarkus that referenced this issue Oct 16, 2022
igorregis pushed a commit to igorregis/quarkus that referenced this issue Oct 16, 2022
igorregis pushed a commit to igorregis/quarkus that referenced this issue Oct 16, 2022
igorregis pushed a commit to igorregis/quarkus that referenced this issue Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/jackson Issues related to Jackson (JSON library) area/jakarta area/panache
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants