@XmlRootElement(name = "graph") @XmlAccessorType(XmlAccessType.NONE) public class Class1 { public List<Integer> i1; public Class1(Integer... i1) { if (this.i1 == null) { this.i1 = new ArrayList<>(); } for (Integer Int : i1) { this.i1.add(Int); } } public Class1() { } @XmlElement public List<Integer> getI1() { return i1; } public void setI1(List<Integer> i1) { if (this.i1 == null) { this.i1 = new ArrayList<>(); } System.out.println("before: " + this.i1); this.i1 = i1.stream().map(arg -> arg*2).collect(Collectors.toList()); System.out.println("after: " + this.i1); } @Override public String toString() { return "Class1{" + "i1=" + i1 + '}'; } } Omitting JAXB initialization. Here is what class we will marshall, and then unmarshallit (omit the details): new Class1 (1,2,3)
result:
before: [ ] after: [ ] Class1{i1=[ ]} replace setter with:
public void setI1(List<Integer> i1) { if (this.i1 == null) { this.i1 = new ArrayList<>(); } System.out.println("before: " + this.i1); this.i1 = i1; System.out.println("after: " + this.i1); } result:
before: [ ] after: [ ] Class1{i1=[1, 2, 3]} The question is, what is this hellish magic? And is it possible to somehow handle the values coming into the setter / getter?