Serializing Objects

Its working... sort of

Page 1 of 1

1 Replies - 3942 Views - Last Post: 31 January 2006 - 03:54 PM Rate Topic: -----

#1 Fame Commeth  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 13-August 05

Serializing Objects

Posted 30 January 2006 - 10:24 PM

I need some help getting an object's data into an xml file. Right now all the XMLEncoder will do is:
<?xml version="1.0" encoding="UTF-8"?> 
     <java version="1.5.0_04" class="java.beans.XMLDecoder"> 
          <object class="PropertyCarousel"/> 
     </java> 


I'm using this to encode:
XMLEncoder encoder = new XMLEncoder( new BufferedOutputStream( new FileOutputStream(filename)));       
     encoder.writeObject((PropertyCarousel)Carousel);
     encoder.close();


This is an edited sample of the PropertyCarousel class:
public class PropertyCarousel {
    private static ArrayList carousel;

public void add(String key, String property) {
	carousel.add( new PropertyItem(key, property));
}
}


Basically what I have done is set up a registry-like way of storing variables. It works quite well, but I need to be able to store the contents of this class... really just the ArrayList... so that the variable states are more permenant. Anyone have any ideas about how I should be doing this more properly?

(I'd prefer to keep this to encoding to xml... or something of the sort. The order of the key values and associated properties in the ArrayList frequently changes, so I cannot really make use of a linear file. Plus, I'd really like to get this right! Grrr...)

PS: I know about the java.util.Properties class, but I'd prefer to use my own. Especially now, I just want this encoder to work!

This post has been edited by Fame Commeth: 31 January 2006 - 07:16 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Serializing Objects

#2 1lacca  Icon User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: Serializing Objects

Posted 31 January 2006 - 03:54 PM

I would redommend reading this tutorial on the XMLEncoder.
Before you are scared away while reading about the delegates, jump at the bottom quarter of the page at the heading: Persistence delegates for classes that implement List and Map.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1