刚找到使用Jackson 2.1+的方法。
使用注释对象引用(这只会选择的id
属性AddressInformation
):
@JsonProperty(value = "defaultaddressid")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
@JsonIdentityReference(alwaysAsId = true)
public AddressInformation getDefaultAddress() {
return defaultAddress;
}
序列化效果很好。