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
11
votes
3 answers

XStream Alias of List root elements

I want to be able to alias the root list element depending upon what type of objects are contained in the list. For example, this is my current output: Gold Silver Bronze And this is what I…
efleming
  • 247
  • 2
  • 4
  • 9
11
votes
6 answers

customising serialisation of java collections using xstream

I have an object that needs to be serialised as XML, which contains the following field: List tags = new List(); XStream serialises it just fine (after some aliases) like this: tagOne
Will Goring
  • 1,040
  • 1
  • 7
  • 18
11
votes
3 answers

Generate Java class from XML file, using XStream

I have many xml files and I would like to use XStream to manage them. Is it possible to generate java classes corresponding to my xml files using XStream?
Ulisse
  • 483
  • 1
  • 7
  • 14
11
votes
3 answers

xstream CannotResolveClassException

I'm trying to use xstream 1.4.2 to convert xml to object. It does work perfectly fine for me until I put the object's class file in a separate package than where the main code runs. Then I get a CannotResolveClassException. I've tried using the…
Slava Markeyev
  • 317
  • 1
  • 4
  • 13
10
votes
1 answer

How to join two event streams on a common event property?

Consider the following two event streams. Every event has a timestamp/ts and value property. I want to combine these two streams where the events have the same timestamps, into a resulting stream with an applied transformation of the value. If one…
hampusohlsson
  • 10,109
  • 5
  • 33
  • 50
10
votes
2 answers

Spring Batch Serialization Problems with Java 8 time package

I have a Spring-batch application that stores several Java 8 time objects in the JobExecutionContext. I am using the default serializer for my JobRespository. I am facing exceptions when parsing back out the data that is being written into the…
Bert S.
  • 155
  • 2
  • 12
10
votes
4 answers

XStream XmlPullParserException

I'm trying to use XStream. I've added the XStream executable Jar file to my project. Executing the following command: XStream xstream = new XStream(); Is resulting in the following exception: Exception in thread "main"…
user3062233
  • 179
  • 1
  • 2
  • 7
10
votes
3 answers

Set default value for fields not in XML in XStream

Is there a way to create a converter or some operation that is performed after every single conversion? For context, I am trying to populate default values for fields that are not in my XML in order to maintain backwards compatibility if my data…
eipark
  • 7,442
  • 3
  • 24
  • 33
10
votes
5 answers

Java XStream - How to ignore some elements

I have the following XML:
Rui Lima
  • 7,185
  • 4
  • 31
  • 42
10
votes
2 answers

deserialize a json array using xstream

There is a lot information at stackoverflow about how to deserialize a json array using Gson. But how can I do the same using XStream with jettison? Here is json: {"entity":[{"id":"1", "name":"aaa"}, {"id":"2", "name":"bbb"}]} Here is XStream code…
Misha
  • 828
  • 10
  • 23
9
votes
3 answers

Storing List with XStream with defined names

I want to store some class to xml: XStream xstream = new XStream(new DomDriver()); List modules = new ArrayList(); modules.add("mod1"); modules.add("mod2"); ModulesConfig modulesConfig = new…
Hleb
  • 295
  • 1
  • 4
  • 15
9
votes
3 answers

In XStream is there a better way to marshall/unmarshall List's in JSON and Java
I'm using XStream and JETTISON's Stax JSON serializer to send/receive messages to/from JSON javascripts clients and Java web applications. I want to be able to create a list of objects to send to the server and be properly marshalled into Java but…
Dougnukem
  • 14,709
  • 24
  • 89
  • 130
9
votes
3 answers

How to add an XML namespace (xmlns) when serializing an object to XML

I'm serializing Objects to XML with the help of XStream. How do I tell XStream to insert an xmlns to the XML output of my object? As an example, I have this simple object I want to serialize: @XStreamAlias(value="domain") public class Domain { …
Wolkenarchitekt
  • 20,170
  • 29
  • 111
  • 174
9
votes
1 answer

How to attach a XStream converter just for a certain element?

It is easy to set a converter for a certain type (http://x-stream.github.io/javadoc/com/thoughtworks/xstream/XStream.html gives an example): xstream.registerConverter(new SqlTimestampConverter()); xstream.registerConverter(new…
Hannes Licht
  • 31
  • 2
  • 5
9
votes
2 answers

com.thoughtworks.xstream.mapper.CannotResolveClassException

This is the frist time I am trying XStream. But when I try to parse my xml file i am getting this exception : Exception in thread "main" com.thoughtworks.xstream.mapper.CannotResolveClassException: root at…
Sembrano
  • 1,127
  • 4
  • 18
  • 28
1
2
3
68 69