Hi Martin, I agree that the observed behaviour during a full round-trip does not feel right, but I guess one has to clearly distinguish between various things here:
- object instantitation
- object initialization
- adding artefacts to such objects as a result of unmarshalling.
As already said, if your POJO does not e.g. create the int instance, Castor will do so by using reflection and eventually calling newInstance(). But if the object instance already is in place, Castor will use it as it is to add objects to the array in your case.
To clarify my argumen(s) even further, how would Castor be able to distinguish between an int initialized with default values (as in your case) and any values (2, 4) ? Personally, I do not think it should be able to do so.
When it comes to your last question, Castor uses whatever is there. If there's an object instance of either an array or e.g. a LinkedList, it will use it and e.g. call the add() methid on the LinkedList. If there isn't such an instance, it will create it. In other words, either leave it up to Castor or control it yourself. But once you control it, that's it.