I like to write my POJOs not to have setters for collections.
public class Parent {
private List<Child> children;
public List<Child> getChildren() {
if (children == null) {
children = new ArrayList<Child>();
}
return children;
}
}
// use case example
public class ParentDecorator {
private final Parent parent;
public ParentDecorator(Parent parent) {
this.parent = parent;
}
public void addAll(List<Child> children) {
parent.getChildren().addAll(children);
}
}
JSON-B serialization works fine, but deserialization does not work as there is no setter for children.
Question: how should I fix this?