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 (despite custom serializers) #650

Open
sdaschner opened this issue Sep 20, 2024 · 0 comments
Open

Recursive mapping issue (despite custom serializers) #650

sdaschner opened this issue Sep 20, 2024 · 0 comments
Labels
bug Something isn't working right

Comments

@sdaschner
Copy link

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.

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 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.

Expected behavior

The following output would be expected from that test:

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

System information:

  • Yasson Version: 3.0.3

Additional context
Originally submitted in quarkusio/quarkus#42442

@sdaschner sdaschner added the bug Something isn't working right label Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working right
Projects
None yet
Development

No branches or pull requests

1 participant