• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XMLEncooder can serialize SimpleAttributeSet?

 
Steli Niculescu
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 2985
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic