File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes XMLEncooder can serialize SimpleAttributeSet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "XMLEncooder can serialize SimpleAttributeSet?" Watch "XMLEncooder can serialize SimpleAttributeSet?" New topic

XMLEncooder can serialize SimpleAttributeSet?

Steli Niculescu

Joined: Jul 14, 2009
Posts: 14
I have a task in which i have to serialize with XMLEncoder an object which contains a SimpleAttributeSet attribute.
I noticed that trying to xml serialize a SimpleAttributeSet doesn't produce any output.

The API says that :
Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see XMLEncoder.

What does this exactly mean ?
Can i serialize SimpleAttributeSet or i have to make a HashMap to manually add the attributes?
Greg Charles

Joined: Oct 01, 2001
Posts: 2968

The warning is a standard one on Swing classes. It means they could change the properties of the class making it incompatible with older versions as far as serialization goes. This incompatibility would only be a problem if you serialized an object to permanent storage, say a file or database, then upgraded Swing, then tried to deserialize the object. Even then it would only be a problem if they actually changed the Serialization UID on the class you serialized ... that is, they actually changed the member variables it had.

That said, XMLEncoder works by encoding properties of Java Bean classes, including the Swing classes. I'm not actually sure how it works on collections classes like HashMap or SimpleAttributeSet (which contains a HashMap). You'll probably have to experiment with that.
I agree. Here's the link:
subject: XMLEncooder can serialize SimpleAttributeSet?
It's not a secret anymore!