From Wikipedia, the free encyclopedia
XStream Library
Initial releaseJanuary 1, 2004; 19 years ago (2004-01-01)
Stable release
1.4.12 / April 12, 2020; 3 years ago (2020-04-12)
Written inJava
Operating systemCross-platform
LicenseBSD-style license

XStream is a Java library to serialize objects to XML (or JSON) and back again.

XStream library[edit]

XStream uses reflection to discover the structure of the object graph to serialize at run time, and doesn't require modifications to objects. It can serialize internal fields, including private and final, and supports non-public and inner classes.[1]

Object graph serialization[edit]

When serializing an object it serializes the full object graph. Duplicate references encountered in the object-model will be maintained. For example, using the following class CD

package com.thoughtworks.xstream;
public class Cd {
	private String id;

	private Cd bonusCd;

	Cd(String id, Cd bonusCd) {
		this.id = id;
		this.bonusCd = bonusCd;

	Cd(String id) {
		this.id = id;

	public String getId() {
		return id;

	public Cd getBonusCd() {
		return bonusCd;

and add some of these object to a list

Cd bj = new Cd("basement_jaxx_singles");
Cd mr = new Cd("maria rita");
List<Cd> order = new ArrayList<>();
// adds the same cd twice (two references to the same object)

// adds itself (cycle)

XStream xstream = new XStream();
xstream.alias("cd", Cd.class);

If the above code is executed with XStream's default relative references mode, it will generate the following XML:

    <id>maria rita</id>
  <cd reference="../cd[2]"/>
  <list reference=".."/>

XStream is free software, distributed under a permissive, revised BSD-style licence.



  1. ^ "Use XStream to serialize Java objects into XML". Ibm.com. Archived from the original on February 19, 2009. Retrieved 2009-12-14.
  2. ^ "XStream - References". Xstream.codehaus.org. Retrieved 2009-12-14.

External links[edit]