I'm using XMLEncoder to write an object graph to a XML file. That works fine, except for the UUID property (which has the name id in my JavaBean) I know that I need a PersistenceDelegate to get it done. I wrote the following one:
class UuidPersistenceDelegate extends PersistenceDelegate {
protected Expression instantiate(Object oldInstance, Encoder out) {
UUID id = (UUID) oldInstance;
return new Expression(oldInstance, id.getClass(), "fromString", new Object[]{ "id" } );
}
}
And set it to the Encoder:
encoder.setPersistenceDelegate(UUID.class, new UuidPersistenceDelegate());
During runtime I get the following exception when calling encoder.writeObject(...):
java.lang.IllegalArgumentException: Invalid UUID string: id
Does anyone know how to get this to work?