Spring with Xstream Example

Xstream is a library to serialize objects to xml and vice-versa without requirement of any mapping file. Notice that castor requires an mapping file.

XStreamMarshaller class provides facility to marshal objects into xml and vice-versa.


Example of Spring and Xstream Integration (Marshalling Java Object into XML)

You need to create following files for marshalling java object into XML using Spring with Xstream:

  1. Employee.java
  2. applicationContext.xml
  3. Client.java

Required Jar files

To run this example, you need to load:

  • Spring Core jar files
  • Spring Web jar files
  • xstream-1.3.jar

download all the jar files for spring including core, web, aop, mvc, j2ee, remoting, oxm, jdbc, orm etc.

download xstream-1.3.jar


Employee.java

If defines three properties id, name and salary with setters and getters.


applicationContext.xml

It defines a bean xstreamMarshallerBean where Employee class is bound with the OXM framework.


Client.java

It gets the instance of Marshaller from the applicationContext.xml file and calls the marshal method.

Output of the example

employee.xml




Contact US

Email:[email protected]

Spring with Xstream
10/30