I retrieve a list of Brothers using hibernate
public class Brother {
public int brotherId;
public string name;
public List<Brother> brothers;
public Brother()
{
brothers = new ArrayList<Brother>();
}
//Getter Setter
}
Hibernate is configured using lazy select in brothers list, this in Java side works, But the problem is when I want to serialize a Brother object to JSON.
I've got org.codehaus.jackson.map.JsonMappingException: Infinite recursion (StackOverflowError)
for Example Bryan can have Mark as brother an viceversa...
How I can solve it? is there any way to indicate max number of recursion to jackson libraries?
my code, it is really simple.
Brother brother = this.myservice.getBrother(4);
ObjectMapper mapper = new ObjectMapper();
System.out.println(mapper.writeValueAsString(brother));