XStream

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

Uses your system voice; voice and rate in settings.

Snapshot

≈ 1 min read

Names in other languages

No names in other languages are held for this entry yet.

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

XStream is a Java library to serialize objects to XML (or JSON) and back again. NOTE: Not to confuse with XStream stream processing platform at Meta.

XStream library

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.

Object graph serialization

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 order = new ArrayList<>(); order.add(mr); // adds the same cd twice (two references to the same object) order.add(bj); order.add(bj); // adds itself (cycle) order.add(order); XStream xstream = new XStream(); xstream.alias("cd", Cd.class); System.out.println(xstream.toXML(order)); If the above code is executed with XStream's default relative references mode, it will generate the following XML: maria rita basement_jaxx_singles XStream is free software, distributed under a permissive, revised BSD-style licence.

Text derived from https://en.wikipedia.org/w/index.php?oldid=1359727903 under CC BY-SA 4.0; modifications have been made.

Sources cited in this revision

2 named source(s) extracted from the cited revision. A source with no author is shown by its publication; nothing is invented.