The Artima Developer Community
Sponsored Link

Agile Buzz Forum
XStream: how to serialize objects to non XML formats

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Joe Walnes

Posts: 151
Nickname: jwalnes1
Registered: Aug, 2003

Joe Walnes, "The Developers' Coach" from ThoughtWorks
XStream: how to serialize objects to non XML formats Posted: Dec 19, 2004 11:13 AM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by Joe Walnes.
Original Post: XStream: how to serialize objects to non XML formats
Feed Title: Joe's New Jelly
Feed URL: http://joe.truemesh.com/blog/index.rdf
Feed Description: The musings of a ThoughtWorker obsessed with Agile, XP, maintainability, Java, .NET, Ruby and OpenSource. Mmm'kay?
Latest Agile Buzz Posts
Latest Agile Buzz Posts by Joe Walnes
Latest Posts From Joe's New Jelly

Advertisement

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

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

Producing:

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

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.

Read: XStream: how to serialize objects to non XML formats

Topic: Web Services from a Spring Enabled Web-App Previous Topic   Next Topic Topic: Descriptor Method Pattern

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use