I have the following DTOs
public class UserDTO {
private String name;
@JsonManagedReference("phone")
private UserPhoneDTO phone;
}
public class PhoneDTO {
private String number;
@JsonManagedReference("user")
private UserPhoneDTO user;
}
public UserPhoneDTO {
@JsonBackReference("user")
private UserDTO userDTO;
@JsonBackReference("phone")
private PhoneDTO phoneDTO;
}
I have a problem, where if I convert json to a UserDTO, the PhoneDTO that is inside the UserPhone gets Nullo. If I convert json to a PhoneDTO, the UserDTO that is inside the UserPhone gets Nullo.
Is there any way I can get around this?
Note: There is an annotation @JsonIdentityInfo (generator = ObjectIdGenerator.Property Generator.class, property="id"), which solves this problem, but when it is used, it creates an id (the name of the property that is defined in the parameter), which causes other problems when sending the same id twice to the server. So I discarded this alternative.