XStream

From Seo Wiki - Search Engine Optimization and Programming Languages
Jump to navigationJump to search
XStream Library
Developer(s) Codehaus
Initial release  ()
Written in Java
Operating system Cross-platform
License BSD-style license
Website http://xstream.codehaus.org/

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

XStream library

XStream stands out for its ease of use and low footprint. It uses reflection to discover the structure of the object graph to serialize at runtime. The XML it generates is very readable.

The library doesn't require modifications to objects, so it's non intrusive to use the library. It can serialize internal fields, including private and final. Supports non-public and inner classes.[2]

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 <source lang="java"> 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; } } </source> and add some of these object to a list <source lang="java"> 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)); </source> If the above code is executed with XStream's default relative references mode, it will generate the following XML: <source lang="xml"><list>

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

</list> </source>

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

Usage

References

  1. [{{Expansion depth limit exceeded||}} "Serializing Java Objects with XStream"]. XML.com, O'Reilly Media, Inc. 2004-08-18. {{Expansion depth limit exceeded||}}. Retrieved 2009-12-14. 
  2. [{{Expansion depth limit exceeded||}} "Use XStream to serialize Java objects into XML"]. Ibm.com. {{Expansion depth limit exceeded||}}. Retrieved 2009-12-14. 
  3. 3.0 3.1 [{{Expansion depth limit exceeded||}} "XStream - References"]. Xstream.codehaus.org. {{Expansion depth limit exceeded||}}. Retrieved 2009-12-14. 

External links


fr:XStream pl:XStream

If you like SEOmastering Site, you can support it by - BTC: bc1qppjcl3c2cyjazy6lepmrv3fh6ke9mxs7zpfky0 , TRC20 and more...