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

quarkus-rest-jackson doesn't support @JsonManagedReference/@JsonBackReference #45753

Open
nicolasduminil opened this issue Jan 21, 2025 · 2 comments
Labels
area/jackson Issues related to Jackson (JSON library) kind/bug Something isn't working

Comments

@nicolasduminil
Copy link

nicolasduminil commented Jan 21, 2025

Describe the bug

Hello,

I'm facing a strange behavior with Quarkus 3.17.6 and quarkus-rest-jackson extension. A REST service CRUDs a couple of JPA entities. These entities maintain a bi-directional one-to-many relationship. In order to avoid infinite recursion, the Jackson @JsonManagedReference/@JsonBackReference annotation are used.

Trying to serialize payloads containing these entities, the following exception is raised:

2025-01-21 15:41:44,261 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (executor-thread-1) HTTP Request to /customers failed, error id:  3cb2f243-8560-4e34-865b-6ffa1b214a3b-1: java.lang.IllegalArgumentException: Cannot handle managed/back reference 'defaultReference':  type: value deserializer of type com.fasterxml.jackson.databind.deser.std.UntypedObjectDeserializerNR does not support them
    at com.fasterxml.jackson.databind.JsonDeserializer.findBackReference(JsonDeserializer.java:433)
    at com.fasterxml.jackson.databind.deser.std.ContainerDeserializerBase.findBackReference(ContainerDeserializerBase.java:104)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerBase._resolveManagedReferenceProperty(BeanDeserializerBase.java:968)
    at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.resolve(BeanDeserializerBase.java:566)
    at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:347)
    at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:284)
    at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:174)
    at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:669)
    at com.fasterxml.jackson.databind.ObjectReader._prefetchRootDeserializer(ObjectReader.java:2450)
    at com.fasterxml.jackson.databind.ObjectReader.forType(ObjectReader.java:771)
...

Expected behavior

I expect that quarkus-rest-jackson be able to use @JsonManagedReference/@JsonBackReference and to successfuly serialize the entities.

In order to make sure that this should work, I implemented exactly the same test case using Jakarta EE 10 and it works as expected.

Actual behavior

The Quarkus implementation doesn't work and raises the mentioned exception, as opposed to the Jakarta EE implemntation, whichworks as expected.

How to Reproduce?

Reproducer: https://github.com/nicolasduminil/orms.git

The repository has two projects: quarkus-orm which reproduces the issue and jakarta-orm which works as expected.

The README.md file in the repository contains instructions of how to reproduce.

Output of uname -a or ver

Linux nicolas-XPS-15-9570 6.8.0-51-generic #52-Ubuntu SMP PREEMPT_DYNAMIC Thu Dec 5 13:09:44 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

java version "21.0.3" 2024-04-16 LTS Java(TM) SE Runtime Environment (build 21.0.3+7-LTS-152) Java HotSpot(TM) 64-Bit Server VM (build 21.0.3+7-LTS-152, mixed mode, sharing)

Quarkus version or git rev

3.17.6

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.5 (57804ffe001d7215b5e7bcb531cf83df38f93546) Maven home: /opt/apache-maven-3.9.5 Java version: 21.0.3, vendor: Oracle Corporation, runtime: /usr/lib/jvm/jdk-21-oracle-x64 Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "6.8.0-51-generic", arch: "amd64", family: "unix"

Additional information

N/A

@nicolasduminil nicolasduminil added the kind/bug Something isn't working label Jan 21, 2025
@quarkus-bot quarkus-bot bot added the area/jackson Issues related to Jackson (JSON library) label Jan 21, 2025
Copy link

quarkus-bot bot commented Jan 21, 2025

/cc @geoand (jackson), @gsmet (jackson), @mariofusco (jackson)

@nicolasduminil
Copy link
Author

Have tried to replace @JsonManagedReference/@JsonBackReference by @JsonIgnoreProperties but, in this case, I got:

 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (executor-thread-1) HTTP Request to /customers failed, error id: 66abbcbc-0bff-43a0-a815-96b50bb4717b-1: org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [java.lang.Long fr.simplex_software.workshop.quarkus.orm.data.Order.id] by reflection for persistent property [fr.simplex_software.workshop.quarkus.orm.data.Order#id] : {id=null, item=myItem01, price=150}
    at org.hibernate.property.access.spi.GetterFieldImpl.get(GetterFieldImpl.java:52)
    at org.hibernate.metamodel.mapping.internal.BasicEntityIdentifierMappingImpl.getIdentifier(BasicEntityIdentifierMappingImpl.java:158)
...
Caused by: java.lang.IllegalArgumentException: Can not get java.lang.Long field fr.simplex_software.workshop.quarkus.orm.data.Order.id on java.util.LinkedHashMap

Not sure where this LinkedMap comes from as there is none in my case.

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) kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant