Compatability

Which JDK is required to use XStream?

1.3 or later.

Does XStream behave differently across different JVMs?

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.

Which JVMs allow XStream to operate in enhanced mode?

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.

What are the advantages of using enhanced mode over pure Java mode?

FeaturePure JavaEnhanced (Sun 1.4 only)
Public classesYesYes
Non public classesNoYes
Static inner classesYesYes
Non-static inner classesNoYes
Anonymous inner classesNoYes
With default constructorYesYes
Without default constructorNoYes
Private fieldsYesYes
Final fieldsNoYes

Are there plans to provide enhanced mode support to other JVMs?

Yes. Let us know which JVM you would like supported.

Serialization

How do I specify that a field should not be serialized?

Make it transient.

What do serialized collections look like?

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>

Do my classes have to implement Serializable if XStream is to serialize them?

No.

Can dynamic proxies be serialized?

Yes.

How does XStream deal with newer versions of classes?

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.

Comparison to other procuts

How does XStream compare to java.beans.XMLEncoder?

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.

Scalability

Is XStream thread safe?

Yes. Once the XStream instance has been created and configured, it may be shared across multiple threads allowing objects to be serialized/deserialized concurrently.

Uses of XStream

Is XStream a data binding tool?

No. It is a serialization tool.

Can XStream generate classes from XSD?

No. For this kind of work a data binding tool such as XMLBeans is appropriate.

Development

Why is the XStream source stored in a Subversion repository? What's wrong with CVS?

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.