XmlSerializerUtil creates only shallow copies
Today I discovered that XmlSerializerUtil.copyBean creates only shallow copies. It doesn't traverse collections contained in the bean that is to be copied - not even those marked by the @AbstractCollection annotation. It just copies the reference to the collection.
That caused me some headaches. Unfortunately copyBean isn't documented and I think it is wrongly named. If it's name was fillBean or something like that it would give some clue that it does not create a real - a deep - copy.
I don't know if it is a bug or a feature. For the task where it is used mostly in the loadState method of a PersistentStateComponent it probably doesn't matter since the original isn't used anywhere, but for anything different like creating a working copy in a settings editor it's only partly useful.
Cheers,
Robert
Please sign in to leave a comment.