im trying to serialize an Object to send it over a socket .
but the problem is when i serialize the object it will fall in a infinite recursion .
i solved the problem of recursion by using the jackson @JsonBackReference
and @JsonManagedReference
annotations mentioned in this post but the problem is ,it still wont serialize the child object . and even when im using @JsonIgnore
it will not serialize the field completely so i'll have a null field when i deserialize it back on the server .
here are my classes:
public class Repository {
public String name;
@JsonIgnore
public ArrayList<UserRole> contributors = new ArrayList<UserRole>();
public User self;
@JsonManagedReference
public ArrayList<FileInfo> files = new ArrayList<FileInfo>();
public RepositoryType repositoryType;
@JsonIgnore
public String path;
}
public class FileInfo {
private Date addedDate;
private String path;
private String name;
@JsonBackReference
public Repository relatedRepository; //this field wont be serialized
}
i've commented the field that wont be serialized . what should i do if i want them both to be serialized ? is there any way to do this ?