Type: New Feature
Affects Version/s: 1.3.1
Fix Version/s: None
JDK version and platform:Non JDK-specific
See this email thread for the background on this.
It would be nice to be able to tell XStream about which map/set implementations are in use on specific fields of specific classes. This would obviate the need for XStream to write out "class=..." attributes when marshalling, and lets xstream know what to instantiate when unmarshalling. It also benefits Hibernate users and allows them to neatly sidestep the problem of hibernate classnames being written out to the XML file.
More detail follows.
Say I have the following class...
I'll get output like this:
Ideally I'd like to be able to omit the class="tree-map" and similar attributes. I realise I can add a default implementation for certain types, but say I have a complex graph of objects that I'm trying to turn into XML, with a mixture of different types of maps and sets. Furthermore, the actual map and set implementations in use may be hibernate lazy-load implementations.
I'd like to be able to say which map/set implementations should be used for specific fields, something like...
...or similar. XStream would omit the class attributes on export regardless of what implementation is in use, and whether it's a regular java or hibernate implementation. And it would know which class to instantiate when encountering the fields on import. This keeps the XML a little but cleaner, and prevents java-specific, and even hibernate-specific things creeping in.