You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JsonSerializer: add support for dependency loops inside the serialized objects #2085
public class A {
private B child;
// getter and setter
}
public class B {
private A parent;
// getter and setter
}
A a = new A();
B b = new B();
a.setChild(b);
b.setParent(a);
JsonSerializer.toJson(a);
Currently the serialization enters in an infinite loop that causes a StackOverflow when trying to convert the object to json.
Jackson for example provides JsonIgnoreProperties to break the cycle.
I can't believe the issue is still present. This would mean there is nobody using bidirectional associations in any of their objects that go to the UI or it would mean they all map to DTO before.
Now 5 years later, I would suggest that we make it easy enough to use existing Jackson functionality throughout rather than adding our own ways of customizing JSON serialization. #8218
Closing as outdated: JsonSerializer no longer exists. Flow now uses Jackson, which offers its own ways to handle cyclic references (e.g. @JsonIgnoreProperties, @JsonManagedReference/@JsonBackReference).
Activity
Legioth commentedon Jul 31, 2017
Is there any real-world case when this happens, or is it only a theoretical issue?
No3x commentedon Mar 2, 2019
I also run into this issue when using a bidirectional JPA relationship. In the following example with collections, but it's the same issue.
Recipe (1) <-----> (*) RecipeItem Stacktrace
A simple test to show the error:
Stacktrace
Note the cycle
Jackson for example provides
JsonIgnorePropertiesto break the cycle.I can't believe the issue is still present. This would mean there is nobody using bidirectional associations in any of their objects that go to the UI or it would mean they all map to DTO before.
Legioth commentedon Mar 4, 2019
What would you expect the JSON to look like?
No3x commentedon Mar 4, 2019
I used the following test with jackson mapper to produce the json I would expect.
{ "id": 42, "name": "My Recipe", "recipeItems": [ { "id": 1, "recipe": { "id": 42, "name": "My Recipe" } } ] }Legioth commentedon Mar 5, 2019
I don't understand the logic for that JSON output. Why is the the item with id
42duplicated but not the item with id1?No3x commentedon Mar 5, 2019
That's because of the
@JsonIgnorePropertiesannotation inRecipeItem- otherwise it would produce a cycle.It tells jackson to omit the recipeItems-property when serializing the recipe.
If you omit the annotation jackson fails with an exception that explains the cycle:
I hope this helps.
Legioth commentedon Dec 19, 2024
Now 5 years later, I would suggest that we make it easy enough to use existing Jackson functionality throughout rather than adding our own ways of customizing JSON serialization. #8218
totally-not-ai commentedon Dec 5, 2026
Closing as outdated:
JsonSerializerno longer exists. Flow now uses Jackson, which offers its own ways to handle cyclic references (e.g.@JsonIgnoreProperties,@JsonManagedReference/@JsonBackReference).