I am looking for a way in Jackson to allow serialization of a relationship depending on the root element. For example, I have a relationship that is not a true parent/child. Both entities can be queried.
Address {
@JsonBackReference
Company company;
String line1;
String city;
String state;
String zip;
String country;
}
Company {
Address mainAddress;
List<Address> locations;
String name;
}
The JsonBackReference makes it so there is no circular reference when serializing to json. However, this also causes me to not know the company of an address. If I am listing companies then the addresses come back and everything is good. But if I am listing addresses I would want to see the company be serialized. Is there a way to achieve this?