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
mtyurt Apr 20 '15 at 7:48 2015-04-20 07:48
source share