Is it possible to user @JsonIdentityInfo with ObjectIdGenerators.PropertyGenerator when the IDs from different entity types overlap?
Assume that I have the following XML and want to deserialize it with Jackson 2.x:
<foo>
<id>3</id>
<name>Peter</name>
<bar>
<id>3</id>
<kind>dog</kind>
<!--belongsTo>3</belongsTo-->
</bar>
</foo>
I've annotated the Foo and Bar class with @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
.
The deserialization fails with com.fasterxml.jackson.databind.JsonMappingException: Already had POJO for id (java.lang.String) [3]
.
If bar has the id 4, everything works fine.
What are the requirements regarding the IDs in XML to be deserialized by Jackson? I have assumed that - since Jackson knows to which entity scope it would be able to work with the same id as long as it belongs to different types.
P.S.: It doesn't seem to matter the belongsTo reference (pointing to a foo object) is set or not.
You might have found the answer already, but in case you didn't...
You should be able to use the scope parameter of the @JsonIdentityInfo for that, i.e.,
@JsonIdentityInfo(scope=Foo.class, property="id", generator=ObjectIdGenerators.PropertyGenerator.class)
public class Foo { ... }
and
@JsonIdentityInfo(scope=Bar.class, property="id", generator=ObjectIdGenerators.PropertyGenerator.class)
public class Bar { ... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With