If this is not what you want, change your canConvert method to return true only if class equals GregorianCalendar. It promises to become a very useful tool for persistence and transport; and I think it embraces, as does Joe Walnes, some virtues of agile programming. You could not add the UTF-8 header this way however XStream uses the fully qualified class name for the element name, including the package name, so the alias method will come in handy for tweaking names. Create a Writer with UTF-8 encoding. If you really want to see this in action, try Reflect.

Uploader: Mejin
Date Added: 17 April 2009
File Size: 61.86 Mb
Operating Systems: Windows NT/2000/XP/2003/2003/7/8/10 MacOS 10/X
Downloads: 53870
Price: Free* [*Free Regsitration Required]

Now let’s convert anything which extends Calendar: Compile the program using this command line at a shell prompt in the working directory: Urs Reupke 4, 2 23 By using our site, you acknowledge that dpmdriver have read and understand our Cookie PolicyPrivacy Policyand our Terms of Service. For additional insights, you might have a look at XStream test programs that use dmdriver or collections from the test suite. Post Your Answer Discard By clicking “Post Your Answer”, you acknowledge that you have read our updated terms of serviceprivacy policy and cookie policyand that your continued use of the website is subject to these policies.


Serializing Java Objects with XStream

The default PrettyPrintWriter will be wrapped by an outputstream with correct encoding. But xtsream nicer, our XML is also simplified using the alias for the Person class. Without it XStream would work fine, but the XML element names would contain the fully qualified name of each class including package which would bulk up the XML a bit.

Email Required, but never shown.

Two Minute Tutorial

It allows existing Java objects to be converted to clean XML and then restored again, without modifications. If you really want to see this in action, try Reflect. Try using an attribute called fullname in the person tag instead of creating a new child node. So we make use of an ‘alias’ to domcriver this full class name to something more ‘human’, for example ‘person’.

The next program, Instant.

You work on a stream and accessing the value of a tag or its members will close the surrounding tag that is still active domdrriver the method is called. The public class Hello imports only one class, com. It has been optimized for this and is in heavy use on production systems.

The current, stable version of XStream is 1. Conclusion This article has introduced you to the basic features and capabilities of XStream.


Note, that attributes will always have to be xstrwam and read first. Using Another Class The next program, Instant. No getters or setters are needed. XStream doesn’t care about the visibility of the fields.

XStream – Two Minute Tutorial

Post as a guest Name. I’m sure you’ll have questions afterwards.

XStream can convert instances of these to XML and back again. It also produces a kind of reflection of objects in XML.

Converter Tutorial

The final program, Deserialize. XStream is being actively developed by a small project team with over a dozen contributors. The alias method creates an alias XML element name for the Date class, changing the default name from Date to date.

XStream’s primary purpose is for serialization.

The program also creates an XML declaration and uses it in its output. Download both the XStream archive and the example programs to a working directory. While XStream is capable of converting this class without any problem, we write our own custom converter just for demonstration.