Jackson deserialize JsonIdentityReference (alwaysAsId = true)

Following this question: Question here

@JsonIdentityReference(alwaysAsId = true) and @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class) works fine with the completion of Serialization, but not so good when the time comes for deserialization, as it cannot resolve the reference to Object ID.

Is there a way to do this for deserialization? Writing a custom deserializer seems redundant.

+16
java json jackson
Aug 19 '13 at 3:34 on
source share
1 answer

Instead of a custom deserializer, you can use a simple deserializer installer:

 public class Container { @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") @JsonIdentityReference(alwaysAsId = true) private Foo foo; public Foo getFoo() { return foo; } public Container setFoo(Foo foo) { this.foo = foo; return this; } @JsonProperty("foo") public void setFoo(String id) { foo = new Foo().setId(id); } } 

Example line {"foo":"id1"} correctly serialized using this method in Jackson 2.5.2

+10
Apr 20 '15 at 7:48
source share



All Articles