Contents - Cultural View

Contents - Cultural View Contents - Cultural View

culturalview.com
from culturalview.com More from this publisher
14.07.2013 Views

XStream 306 XStream Developer(s) Codehaus Initial release January 1, 2004 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 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;

XStream 307 } 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. Usage • Confluence [3] • Apache Muse [3] External links • XStream Library Home Page [4] References [1] "Serializing Java Objects with XStream" (http:/ / www. xml. com/ lpt/ a/ 1462). XML.com, O'Reilly Media, Inc. 2004-08-18. . Retrieved 2009-12-14. [2] "Use XStream to serialize Java objects into XML" (http:/ / www. ibm. com/ developerworks/ java/ library/ x-xstream/ index. html). Ibm.com. . Retrieved 2009-12-14. [3] "XStream - References" (http:/ / xstream. codehaus. org/ references. html). Xstream.codehaus.org. . Retrieved 2009-12-14. [4] http:/ / xstream. codehaus. org/

XStream 306<br />

XStream<br />

Developer(s) Codehaus<br />

Initial release January 1, 2004<br />

Written in Java<br />

Operating<br />

system<br />

Cross-platform<br />

License BSD-style license<br />

Website http:/ / xstream. codehaus.<br />

org/<br />

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

XStream library<br />

XStream stands out for its ease of use and low footprint. It uses reflection to discover the structure of the object<br />

graph to serialize at runtime. The XML it generates is very readable.<br />

The library doesn't require modifications to objects, so it's non intrusive to use the library. It can serialize internal<br />

fields, including private and final. Supports non-public and inner classes. [2]<br />

Object graph serialization<br />

When serializing an object it serializes the full object graph. Duplicate references encountered in the object-model<br />

will be maintained. For example using the following class CD<br />

package com.thoughtworks.xstream;<br />

public class Cd {<br />

private String id;<br />

private Cd bonusCd;<br />

Cd(String id, Cd bonusCd) {<br />

}<br />

this.id = id;<br />

this.bonusCd = bonusCd;<br />

Cd(String id) {<br />

}<br />

this.id = id;<br />

public String getId() {<br />

}<br />

return id;<br />

public Cd getBonusCd() {<br />

}<br />

return bonusCd;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!