1.3 or later.
XStream has two modes of operation: Pure Java and Enhanced. In pure Java mode, XStream behaves in the same way across different JVMs, however it's features are limited to what reflection allows, meaning it cannot serialize certain classes or fields. In enhanced mode, XStream does not have these limitations, however this mode of operation is not available to all JVMs.
Currently on the Sun, Apple, HP, IBM and Blackdown 1.4 JVMs and onwards. For all other JVMs, XStream should be used in pure Java mode.
Feature | Pure Java | Enhanced (Sun 1.4 only) |
---|---|---|
Public classes | Yes | Yes |
Non public classes | No | Yes |
Static inner classes | Yes | Yes |
Non-static inner classes | No | Yes |
Anonymous inner classes | No | Yes |
With default constructor | Yes | Yes |
Without default constructor | No | Yes |
Private fields | Yes | Yes |
Final fields | No | Yes |
Yes. Let us know which JVM you would like supported.
Make it transient
.
Example:
class Person { private String name; private List toys = new ArrayList(); // ... } class Computer { String type; } class Car { String color; } xstream.alias("person", Person.class); xstream.alias("computer", Computer.class); xstream.alias("car", Car.class); Person person = new Person("Joe"); person.addToy(new Computer("apple")); person.addToy(new Computer("spectrum")); person.addToy(new Car("blue")); String xml = xstream.toXML(joe);
Results in:
<person> <name>Joe</name> <toys> <computer> <type>apple</type> </computer> <computer> <type>spectrum</type> </computer> <car> <color>blue</color> </car> </toys> </person>
No.
Yes.
For more advanced class migrations, you may have to do custom pre-processing of the XML before sending it to XStream (for example, with XSLT or DOM manipulations).
Future versions of XStream will include features to make these type of migrations easier.
XStream is designed for serializing objects using internal fields, whereas
XMLEncoder is designed for
serializing JavaBeans using public API methods (typically in the form
of getXXX()
, setXXX()
, addXXX()
and removeXXX()
methods.
Yes. Once the XStream instance has been created and configured, it may be shared across multiple threads allowing objects to be serialized/deserialized concurrently.
No. It is a serialization tool.
No. For this kind of work a data binding tool such as XMLBeans is appropriate.
The main reason for the use of Subversion instead of CVS is that most of the development work for XStream takes place while not connected to the Internet. With Subversion, commands like add, remove, rename, diff and revert do not require a connection to the server.