XStream is a simple library written in Java used to serialize Java objects to XML (or JSON) and back again. It does not require defining an XML schema and uses reflection to determine the fields that need to be stored. It’s a free software available under BSD-style license and used in a lots of open source and commercial projects where there is a need to convert existing Java objects to clean XML and restore them again without modification of the object code. XStream provides a good performance for the large volume of files.
The architecture of XStream is made up of the four essential parts:
- Drivers (Reader and Writer)
The key features of this library are:
- If XStream is configured properly, it produces clean and compact XML that can be easily read because no information is duplicated if it can be obtained via reflection.
- XStream has a high-level facade that makes it easy to use.
- XStream doesn't require any modifications to objects so it supports inner and non-public classes and serializes internal fields including final and private.
- XStream doesn’t require mapping to serialize most objects.
- It provides full support for object graphs and allows to maintain circular and duplicate references treating them as graphs instead of simple trees.
- XStream is suitable for systems with high message throughput and large object graphs.
- The library supports other output formats such as morphine and JSON.
- It provides powerful opportunities for customization of the XML output.
- When handling exceptions, it provides error messages about malformed XML and can help fix the problem with detailed diagnostics.
- XStream has security features that ensure a fair control over the unmarshalled types and prevent security issues.
- XStream can integrate with other XML APIs.
XStream is typically used for:
- Unit tests