The Artima Developer Community
Sponsored Link

Web 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
Friedrich Anode

Posts: 71
Nickname: anode
Registered: Jul, 2003

Friedrich Anode is a web entrepeneur and musician.
XStream: how to serialize objects to non XML formats Posted: Sep 26, 2006 2:03 AM
Reply to this message Reply

This post originated from an RSS feed registered with Web Buzz by Friedrich Anode.
Original Post: XStream: how to serialize objects to non XML formats
Feed Title: Anode Says...
Feed URL: http://apps5.oingo.com/apps/domainpark/domainpark.cgi?client=GALT6690&s=asp.net
Feed Description: Web technology news and opinion.
Latest Web Buzz Posts
Latest Web Buzz Posts by Friedrich Anode
Latest Posts From Anode Says...

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: Powered by Ruby on Rails Buttons Previous Topic   Next Topic Topic: Mastering Ajax: Build DOM-based Web applications

Sponsored Links



Google
  Web Artima.com   

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