mty*_*urt 11
您可以使用简单的setter反序列化器代替自定义反序列化器:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
{"foo":"id1"}使用此方法正确序列化示例字符串Jackson 2.5.2