XMLEncoder - set value during writing an object

173 Views Asked by At

I need to write object to XML so I use XMLEncoder but one of the variables (String) in this object should be crypted. Is it possible to capture object while writing and then replace the value (but don't set the value in object)?

1

There are 1 best solutions below

0
On

Yes. XMLEncoder uses serialization so you can use normal serialization rules to override the default behaviour of the serialization in readObject and writeObject.

http://java.sun.com/products/jfc/tsc/articles/persistence4/

Although some could argue if it is important enough to encrypt an object on a file, maybe you should keep it encrypted in memory as that is just as easy to look at.