XStream is a simple library to serialize objects to XML and back again.
Features
- Ease of use. A high level facade is supplied that simplifies common use cases.
- No mappings required. Most objects can be serialized without need for specifying mappings.
- Performance. Speed and low memory footprint are a crucial part of the design, making it suitable for
large object graphs or systems with high message throughput.
- Clean XML. No information is duplicated that can be obtained via reflection. This results
in XML that is easier to read for humans and more compact than native Java serialization.
- Requires no modifications to objects. Serializes internal fields, including private and
final. Supports non-public and inner classes. Classes are not required to have default constructor.
- Full object graph support. Duplicate references encountered in the object-model will
be maintained. Supports circular references.
- Integrates with other XML APIs. By implementing an interface, XStream can serialize
directly to/from any tree structure (not just XML).
- Customizable conversion strategies. Strategies can be registered allowing customization of how
particular types are represented as XML.
- Error messages. When an exception occurs due to malformed XML, detailed diagnostics are provided
to help isolate and fix the problem.
- Alternative output format. The modular design allows other output formats. XStream ships currently
with JSON support and morphing.
Typical Uses
- Persistence
- Transport
- Configuration
- Unit Tests
Known Limitations
If using the enhanced mode, XStream can re-instantiate classes that do not have a default constructor.
However, if using a different JVM like an old JRockit version, a JDK 1.3 or you have restrictions because of a
SecurityManager, a default constructor is required.
The enhanced mode is also necessary to restore final fields for any JDK < 1.5. This implies deserialization of
instances of an inner class.
Getting Started
May 24, 2007 XStream 1.2.2 released
A maintenance release of XStream that contains a lot of bug fixes and has some minor highlights:
- JSON serialization and deserialization support with the help of the new JettisonMappedXmlDriver
- Supports customized field sorting
- Omitting fields at deserialization time
View the complete change log and download.
Note, that next version of XStream will behave slightly different by default. XStream emits
all fields in declaration order like Java serialization. But in contrast to Java it will omit the fields of parent
classes last while Java serialization emits them first. This makes it difficult to match a given XML schema that
defined inherited types or leads sometimes to obscure initialization problems. However, XStream itself will not be
affected by the changed order of elements in the XML, any deserialization of current XML representations will work
fine. Anyway we will provide with XStream 1.3 a FieldKeySorter implementation that mimics the old behaviour. In
the meanwhile you can enforce the new field sorting by installing the NaturalFieldKeySorter.