Questions tagged [xstream]

XStream is a simple Java library to serialize objects to XML and back again.

XStream

XStream is a simple library to serialize objects to XML and back again. It is typical used for Transport, Persistence, Configuration and Unit Tests.

Features

  • Ease of use. A high level facade is supplied that simplifies common use cases.

  • No mappings required. Most objects can be serialized without need for specifying mappings.

  • Performance. Speed and low memory footprint are a crucial part of the design, making it suitable for large object graphs or systems with high message throughput.

  • Clean XML. No information is duplicated that can be obtained via reflection. This results in XML that is easier to read for humans and more compact than native Java serialization.

  • Requires no modifications to objects. Serializes internal fields, including private and final. Supports non-public and inner classes. Classes are not required to have default constructor.

  • Full object graph support. Duplicate references encountered in the object-model will be maintained. Supports circular references.

  • Integrates with other XML APIs. By implementing an interface, XStream can serialize directly to/from any tree structure (not just XML).

  • Customizable conversion strategies. Strategies can be registered allowing customization of how particular types are represented as XML.

  • Error messages. When an exception occurs due to malformed XML, detailed diagnostics are provided to help isolate and fix the problem.

  • Alternative output format. The modular design allows other output formats. XStream ships currently with JSON support and morphing.

References

1024 questions
7
votes
1 answer

Make XStream ignore one specific private variable

I have a little problem with a class I am currently writing a save function for. I'm using XStream (com.thoughtworks.xstream) to serialize a class to XML using the DOMDriver. The class looks like this: public class World { private Configuration…
Tigraine
  • 23,358
  • 11
  • 65
  • 110
7
votes
1 answer

XStream: how can I hide 2 unnecessary parent nodes in marshaled XML?

In a unit test project, I need some help figuring out how how I can hide 2 unnecessary parent nodes in marshaled XML? Can anyone help me figure out how to do it? My marshalled output looks like this: Suite 1
djangofan
  • 28,471
  • 61
  • 196
  • 289
7
votes
9 answers

XStream or Simple

I need to decide on which one to use. My case is pretty simple. I need to convert a simple POJO/Bean to XML, and then back. Nothing special. One thing I am looking for is it should include the parent properties as well. Best would be if it can work…
Adeel Ansari
  • 39,541
  • 12
  • 93
  • 133
7
votes
3 answers

XStream serialize null values

Suppose I have class Student { String name; int age; String teacher; } Then : public class App1 { public static void main(String[] args) { Student st = new Student(); st.setName("toto"); XStream xs = new…
tweetysat
  • 2,187
  • 14
  • 38
  • 75
7
votes
3 answers

XML mapping attribute of nested element

I'm using XStream and I have an XML sample: Joe Walnes and I whant to map it to the class public class Person { …
Viktor Stolbin
  • 2,899
  • 4
  • 32
  • 53
6
votes
8 answers

What are the relative advantages of XMLEncoder and XStream?

Suppose I want to store many small configuration objects in XML, and I don't care too much about the format. The XMLDecoder class built into the JDK would work, and from what I hear, XStream works in a similar way. What are the advantages to each…
erickson
  • 265,237
  • 58
  • 395
  • 493
6
votes
2 answers

nodecom.thoughtworks.xstream.mapper.CannotResolveClassException while using xstream under Kettle

I am using XStream under Kettle to deserialize XML to a Java object and it always gives me the exception: nodecom.thoughtworks.xstream.mapper.CannotResolveClassException Then I tried my code separately from Kettle and as a simple Java application.…
Kyleinincubator
  • 313
  • 1
  • 5
  • 12
6
votes
3 answers

Format Date Fields to String in XStream

I have a date field, which when converted to xml using XStream, gives time in milliseconds and zone. I just need to convert or format it as "MMMM dd, yyyy HH:mm:ss". How to do that using XStream? I don't want to change the getters and setters.…
Ahamed
  • 39,245
  • 13
  • 40
  • 68
6
votes
3 answers

Java XStream with HashMap

I want to use XStream to convert a java hash to a json hash. I feel like this should be easier than it seems. What I'm looking for is a way to make: Map map = new HashMap(); map.put("first",…
Ken Mazaika
  • 1,142
  • 10
  • 12
6
votes
4 answers

What is the best Java-way to create JSON/XML REST Web services that is similar to WCF?

I'm looking for a best way that is available for Java developers to implement REST services that will be communicating via JSON or XML. I'm looking for production-ready products. I know that Spring 3.0 is coming, but it's not done yet - no luck. Is…
IgorM
  • 1,068
  • 2
  • 18
  • 29
6
votes
1 answer

ArrayIndexOutOfBoundsException when using XStream

I'm not sure how this is even possible, but the program I am running is giving me an odd error. I am getting an ArrayIndexOutOfBoundsException: -1 on a for each loop. The entire error is below: Exception in thread "main"…
Tanner
  • 477
  • 7
  • 21
6
votes
1 answer

How to handle cyclic references in XStream?

The XStream serialization library claims to be robust in serializing complex Java objects out of the box (e.g. no modifications to objects or mapping needed). In particular, according to XStream docs, XStream can handle circular object…
mchen
  • 9,808
  • 17
  • 72
  • 125
6
votes
2 answers

XStream: Collapsing XML hierarchy as I parse

I have an XML document (generated by Adobe XFA forms), that contains data like the following: <StartDate/> <EndDate/> </PositionBorder> </Position> Since this file is defined…</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/java" class="post-tag grid--cell" title="show questions tagged 'java'" rel="tag">java</a> <a href="../../questions/tagged/xml" class="post-tag grid--cell" title="show questions tagged 'xml'" rel="tag">xml</a> <a href="../../questions/tagged/parsing" class="post-tag grid--cell" title="show questions tagged 'parsing'" rel="tag">parsing</a> <a href="../../questions/tagged/converters" class="post-tag grid--cell" title="show questions tagged 'converters'" rel="tag">converters</a> <a href="../../questions/tagged/xstream" class="post-tag grid--cell" title="show questions tagged 'xstream'" rel="tag">xstream</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Jan 11 '10 at 22:03">asked Jan 11 '10 at 22:03</time> <a href="../../users/136449/steve" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/136449.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="Steve" /> </a> <div class="s-user-card--info"> <a href="../../users/136449/steve" class="s-user-card--link">Steve</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">2,678</li> <li class="s-award-bling s-award-bling__gold" title="8 gold badges">8</li> <li class="s-award-bling s-award-bling__silver" title="40 silver badges">40</li> <li class="s-award-bling s-award-bling__bronze" title="54 bronze badges">54</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="mln24"> <div class="question-summary" id="question-summary-18178868"> <div class="statscontainer"> <div class="stats"> <div class="vote"> <div class="votes"> <span class="vote-count-post"><strong>6</strong></span> <div class="viewcount">votes</div> </div> </div> <div class="status "> <strong>1</strong> answer </div> </div> </div> <div class="summary"> <h3><a href="../../questions/18178868/how-to-retrieve-object-state-from-serialized-java-objects-without-class-file-s" class="question-hyperlink">How to retrieve object state from serialized Java objects without class file(s)</a></h3> <div class="excerpt">I have a binary file that contains Java Serialized objects (which are value objects), but I do not have access to the Class that was serialized to create those objects. Without the class file, JVM does not allow me to read the objects with…</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/java" class="post-tag grid--cell" title="show questions tagged 'java'" rel="tag">java</a> <a href="../../questions/tagged/xml" class="post-tag grid--cell" title="show questions tagged 'xml'" rel="tag">xml</a> <a href="../../questions/tagged/serialization" class="post-tag grid--cell" title="show questions tagged 'serialization'" rel="tag">serialization</a> <a href="../../questions/tagged/deserialization" class="post-tag grid--cell" title="show questions tagged 'deserialization'" rel="tag">deserialization</a> <a href="../../questions/tagged/xstream" class="post-tag grid--cell" title="show questions tagged 'xstream'" rel="tag">xstream</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Aug 12 '13 at 02:39">asked Aug 12 '13 at 02:39</time> <a href="../../users/2062562/gursev-kalra" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/2062562.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="Gursev Kalra" /> </a> <div class="s-user-card--info"> <a href="../../users/2062562/gursev-kalra" class="s-user-card--link">Gursev Kalra</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">99</li> <li class="s-award-bling s-award-bling__silver" title="1 silver badges">1</li> <li class="s-award-bling s-award-bling__bronze" title="5 bronze badges">5</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="mln24"> <div class="question-summary" id="question-summary-1753511"> <div class="statscontainer"> <div class="stats"> <div class="vote"> <div class="votes"> <span class="vote-count-post"><strong>6</strong></span> <div class="viewcount">votes</div> </div> </div> <div class="status answered-accepted"> <strong>2</strong> answers </div> </div> </div> <div class="summary"> <h3><a href="../../questions/1753511/how-can-i-get-xstream-to-output-scala-lists-nicely-can-i-write-a-custom-conver" class="question-hyperlink">How can I get XStream to output Scala lists nicely? Can I write a custom converter?</a></h3> <div class="excerpt">This code: println(new XStream.toXML(List(1,2,3))) produces this XML: <scala.coloncolon serialization="custom"> <unserializable-parents/> <scala.coloncolon> <int>1</int> <int>2</int> <int>3</int> <scala.ListSerializeEnd/> …</div> <div class="grid ai-start jc-space-between fw-wrap"> <div class="grid gs4 fw-wrap tags "> <a href="../../questions/tagged/generics" class="post-tag grid--cell" title="show questions tagged 'generics'" rel="tag">generics</a> <a href="../../questions/tagged/list" class="post-tag grid--cell" title="show questions tagged 'list'" rel="tag">list</a> <a href="../../questions/tagged/scala" class="post-tag grid--cell" title="show questions tagged 'scala'" rel="tag">scala</a> <a href="../../questions/tagged/xstream" class="post-tag grid--cell" title="show questions tagged 'xstream'" rel="tag">xstream</a> </div> <div class="started mt0"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Nov 18 '09 at 03:54">asked Nov 18 '09 at 03:54</time> <a href="../../users/118130/waterlooalex" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/118130.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="waterlooalex" /> </a> <div class="s-user-card--info"> <a href="../../users/118130/waterlooalex" class="s-user-card--link">waterlooalex</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">13,642</li> <li class="s-award-bling s-award-bling__gold" title="16 gold badges">16</li> <li class="s-award-bling s-award-bling__silver" title="78 silver badges">78</li> <li class="s-award-bling s-award-bling__bronze" title="99 bronze badges">99</li> </ul> </div> </div> </div> </div> </div> </div> </div> <div class="s-pagination pager fr"> <a class="s-pagination--item" href="../../questions/tagged/xstream_page=3" rel="prev" title="Go to page 3">Prev </a> <a class="s-pagination--item" href="../../questions/tagged/xstream_page=1" rel="" title="Go to page 1">1</a> <a class="s-pagination--item" href="../../questions/tagged/xstream_page=2" rel="" title="Go to page 2">2</a> <a class="s-pagination--item" href="../../questions/tagged/xstream_page=3" rel="" title="Go to page 3">3</a> <div class="s-pagination--item s-pagination--item__clear">…</div> <a class="s-pagination--item" href="../../questions/tagged/xstream_page=68" rel="" title="Go to page 68">68</a> <a class="s-pagination--item" href="../../questions/tagged/xstream_page=69" rel="" title="Go to page 69">69</a> <a class="s-pagination--item" href="../../questions/tagged/xstream_page=5" rel="next" title="Go to page 5"> Next</a> </div> </div> </div> </div> </div> <script src="../../static/js/stack-icons.js"></script> <script src="../../static/js/fromnow.js"></script> </body> </html>