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

Recursive mapping issue with JSON-B (despite custom serializers) #42442

Open
sdaschner opened this issue Aug 9, 2024 · 1 comment
Open

Recursive mapping issue with JSON-B (despite custom serializers) #42442

sdaschner opened this issue Aug 9, 2024 · 1 comment
Labels
kind/bug Something isn't working

Comments

@sdaschner
Copy link
Contributor

Describe the bug

Class structures that contain a recursive reference can't be mapped to JSON, even though when one defines custom JSON-B serializers or type adapters. This doesn't really make sense, since serializing (back) references to, for example, scalar values stops the recursion.

Expected behavior

Make it possible to serialize recursive references when custom serializers / type adapters are present.

Actual behavior

No response

How to Reproduce?

Reproducer here: https://github.com/sdaschner/quarkus-playground/releases/tag/jsonb-recursive-mapping

mvn quarkus:dev
curl localhost:8080/json-test

(or run JsonIT in the project)

This will cause Quarkus to throw an exception like:

Caused by: jakarta.json.bind.JsonbException: Unable to serialize property 'schedule' from com.sebastian_daschner.coffee.JsonTestResource.Item
	at org.eclipse.yasson.internal.serializer.ObjectSerializer.lambda$serialize$0(ObjectSerializer.java:43)
[...]
	at org.eclipse.yasson.internal.serializer.ObjectSerializer.lambda$serialize$0(ObjectSerializer.java:41)
	... 25 more
Caused by: jakarta.json.bind.JsonbException: Recursive reference has been found in class class com.sebastian_daschner.coffee.JsonTestResource$Schedule.
	at org.eclipse.yasson.internal.serializer.RecursionChecker.serialize(RecursionChecker.java:36)
[...]

As you can see in the code (Schedule -> Item), the back reference Item#schedule is annotated with @JsonbTypeSerializer(ScheduleNameSerializer.class). Only if also the reference Schedule#item is annotated with a similar serializer, it works. Adding @JsonbTransient on the back reference also works.

However, the following output would be expected from that test:

{
  "item": {
    "name": "Item",
    "schedule": "Name"
  },
  "name": "Name"
}

Output of uname -a or ver

No response

Output of java -version

No response

Quarkus version or git rev

3.13.0

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

No response

Additional information

No response

@sdaschner sdaschner added the kind/bug Something isn't working label Aug 9, 2024
@geoand
Copy link
Contributor

geoand commented Aug 9, 2024

Thanks for reporting.

This actually looks like a Yasson issue to be honest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants