Programming - Beans serialisation to/from XML

If the Beans interface is implemented, then the classes can be serialised to/from XML using:

There may be downsides to XMLEncoder/Decoder? the documentation seems to suggest that it clones all the data which suggests there may be memory size and performance issues.

java.beans.XMLDecoder

XMLDecoder d = new XMLDecoder(new BufferedInputStream(new FileInputStream("Test.xml")));
Object result = d.readObject();
d.close();

java.beans.XMLEncoder

XMLEncoder e = new XMLEncoder(new BufferedOutputStream(new FileOutputStream("Test.xml")));
e.writeObject(new JButton("Hello, world"));
e.close();


metadata block
see also:

 

Correspondence about this page

This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2023 Martin John Baker - All rights reserved - privacy policy.