My Entity Object has some private fields with public getter and setter and also a private list without get or set, because i want to check the items before they get added to the list.
Looks something like this:
public class MyData{
private String name;
private String description;
private List<MoreData> moreData;
public String getName(){...}
public String setName(){...}
public String getDescription(){...}
public String setDescription(){...}
public void addMoreData(MoreData data){
// validate Data
moreData.add(data);
}
}
Now i would like to serialize this Class including the list to json to send it to my frontend, but apparently private fields are ignored.
An solution would be a seperate DTO but this is a lot of boilerplate code i would like to avoid. So how can i tell my RestController / Jackson to serialize my private fields (lists)?