I need to serialize an entity with only two column when it's called by a foreign key. I'am working in Wildfly, so I'am searching for a jackson solutions.
Suppose I have entity class A
public class A{
private Long id;
private String name;
private String anotherinfo;
private String foo;
...
}
and another class B:
public class B{
private Long id;
private String name;
private A parent;
}
I want to serialize A with all his field when i search for A, but when i need to retrieve an istance of B, i need only two field (an ID and a label)
If I use annotations:
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
@JsonIdentityReference(alwaysAsId=true)
private A parent;
i'll return only the id.
The result i want will be like:
B: {
"id" : 1,
"name" : "test",
"parent" : {
"id" : 1,
"name" : 2
}
}