When serializing a Java object which has other object references, I need to serialize only one attribute of the nested object(usual case of foreign key, so serialize the \"i
Just Found a way using Jackson 2.1+ .
Annotate object references with(this will pick only the id
attribute of AddressInformation
):
@JsonProperty(value = "defaultaddressid")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
@JsonIdentityReference(alwaysAsId = true)
public AddressInformation getDefaultAddress() {
return defaultAddress;
}
Serialization works very well.