I have checked the @JsonIdentityInfo, the @JsonManagedReference, and the @JsonBakcReference, but it seems none of them manages my issue.
Basically I have the following table:
id | name | parent_id
1000 | Item 1 | (null)
2000 | Item 2 | 1000
2001 | Item 3 | 2000
2002 | Item 4 | 2000
3000 | Item 5 | 1000
3001 | Item 6 | 3000
I have the following JPA entity:
@Entity
@Table(name = "table")
public class table {
@Id
@Column(name="id")
private Long id;
@Column(name="name")
private String name;
@Column(name="parent_id")
private Long id;
//getters setters
}
What I want to achieve is to produce a JSON string that is the following:
[{title: "Item 1", key: "1000"}, {title: "Item 2", key: "2000", children[{title: "Item 3", key:"2001"},{title: "Item 4", key": "2002"}]},{title: "Item 5", key:"3000", children[{title: "Item 6", key: "3001"}]}]
My main problem is how do I write the serialization to JSON? knowing that I can have several levels in each other