Posts Tagged ‘ XStream ’

Java and .NET RESTful interoperability with XStream

My ex-colleagues Paul Hammant and Ian Cartwright have written an article on their experiences of building SOA applications using RESTful services in .NET and Java that could interoperate over web services and message queues. XStream made this possible.

Buzzwordtastic.

http://www.infoq.com/articles/REST-INTEROP

XStream 1.1.2 released. Java 5 Enums, JavaBeans, field aliasing, StAX, and more…

New features:

  • Java 5 Enum support.
  • JavaBeanConverter for serialization using getters and setters.
  • Aliasing of fields.
  • StAX integration, with namespaces.
  • Improved support on JDK 1.3 and IBM JDK.

Changelog:
http://xstream.codehaus.org/changes.html

Full download:
http://dist.codehaus.org/xstream/distributions/xstream-1.1.2.zip

Jar only:
http://dist.codehaus.org/xstream/jars/xstream-1.1.2.jar

XStream 1.1.1 released

I’m pleased to announce the release of XStream 1.1.1 – the powerful, yet easy to use Java to XML serialization library.

Some of the improvements in this release:

  • Converters can be registered with a priority, allowing more generic filters to handle classes that don’t have more specific converters.
  • Converters can now access underlying HierarchicalStreamReader/Writer implementations to make implementation specific calls.
  • Improved support for classes using ObjectInputFields and ObjectInputValidation to follow the serialization specification.
  • Default ClassLoader may be changed using XStream.setClassLoader().
  • Loads of bugfixes and performance enhancements.

Full change log: http://xstream.codehaus.org/changes.html
Download: http://xstream.codehaus.org/download.html

XStream 1.1 released

I’m pleased to announce the release of XStream 1.1.

New features include:

  • Improved support for serializing objects following the Java Serialization Specification:
    • Calls custom serialization methods, readObject(), writeObject(), readResolve() and writeReplace() in class, if defined.
    • Supports ObjectInputStream.getFields() and ObjectOutputStream.putFields() in custom serialization.
  • Provides implementations of ObjectInputStream and ObjectOutputStream, allowing drop in replacements for standard serialization,
    including support for streams of objects. [More…]
  • Reads and writes directly to most XML Java APIs: DOM, DOM4J, JDOM, XOM, Electric XML, StAX, Trax (write only), SAX (write only).
    [More…]

View the complete change log and
download.

XStream: how to serialize objects to non XML formats

As you know, XStream makes it easy to serialize objects to XML:

Person person = ...;
xstream.toXML(out);

Producing:

Joe
Walnes

123
433535


4545
4534

I often use this approach whilst debugging to dump out the contents of an object. It works, but my eyes just aren’t that good at parsing XML.

By creating an alternative writer implementation, XStream can be used to serialize objects in other formats:

Person person = ...;
xstream.marshal(stuff, new AnAlternativeWriter(out));

Producing the slightly more digestible:

com.blah.Person
firstName = Joe
lastName = Walnes
homePhone
areaCode = 123
number = 433535
cellPhone
areaCode = 4545
number = 4534

To gain roundtrip serialization/deserialization support in alternative formats to XML, you need to provide your own implementations of both HierarchicalStreamWriter and HierarchicalStreamReader.

XStream article on O’Reilly XML.com

http://www.xml.com/pub/a/2004/08/18/xstream.html

XStream roadmap: What do YOU want to see?

I’m assessing where the next version of XStream should go. There are three major chunks of work I’d like to tackle (described below), however I can only take on one at a time and need to prioritize.

What do you want to see? Leave your comments on my blog.

1. Full support for the Java serialization specification.

Current situation: XStream uses reflection to access an objects fields and convert them to and from XML.

Problem: While this works well with most custom objects, there are many classes (particularly in the standard java and javax packages) that rely on advanced features of the serialization API, by implementing the methods, readObject(), writeObject(), writeReplace() or the methods found in java.io.Externalizable.

Solution: The default Converter in XStream could be enhanced to support these features.

Outcome: XStream should be able to serialize any object that standard Java serialization can, without any modifications.

2. Improved JVM support.

Current situation: XStream uses reflection to instantiate objects when deserializing. Using plain reflection, this requires each object to have a default constructor, which XStream will call. An ‘enhanced-mode’ is also supported that uses JVM specific calls to construct objects without ever invoking a constructor, guaranteeing no side-effects.

Problem: Currently the ‘enhanced-mode’ is only available if using the Sun 1.4 JVM or later.

Solution: Enhance the enhanced mode to support more popular JVMs, including Sun 1.3, IBM 1.4, and JRockit.

Outcome: More users can use XStream without having to make intrusive modifications to their classes.

3. Configurable mappings.

Current situation: XStream was originally designed as a tool for transparent serialization of objects (specifically for persistence or to send across the wire in messaging systems). As such, the goal was to allow XStream to figure out what the XML should look like on the fly, without forcing the mappings to be defined for each class.

Problem: An unforseen popular usage of XStream is for assembling objects from XML configuration files. However, because XStream has been designed to just figure out the XML on the fly, it does not allow users to (easily) specify their own XML structure.

Solution: To add more simple to use ‘tweaks’ to the generated XML. For example, to allow attributes to be used in some elements, alias elements based on where they appear or remove redundant tags to make the XML easier to understand.

Outcome: More flexibility for the resulting XML, without forcing users to write custom converters.