I have a data structure (not designed by me, so no chance to change it!). In which one class (e.g. foo) contains other (e.g. bar), and bar contains an array foo. I solved this using @JsonIdentityInfo
in this manner:
@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "object.id" )
public class Foo {
@JsonProperty
Object id;
@JsonProperty
Bar bar;
}
@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "object.id" )
public class Bar{
@JsonProperty
Object id;
@JsonProperty
List<Foo> foos;
}
This deserializes properly but it serializes not completely correct. The issue is this generate an extra id object.id
. I would like to use the ID
as the object.id
. How can I achieve this using Jackson annotations?
I want to parse an serialize this:
Object Foo:
{
"id":1,
"bar":
{
"id":2,
"foos":[1]
}
}
and not this:
{
"id":1,
"object.id":2,
"bar":
{
"id":2,
"object.id":2,
"foos":[1]
}
}