Listing 1

XMLEncoder e = new XMLEncoder(os);
Person p = PersonFactory.createPerson("Smith");
Cust.setFirstName("John");
e.setPersistenceDelegate(Person.class, new DefaultPersistenceDelegate(){
  protected Expression instantiate(Object oldInstance, Encoder out){
   String lastName = ((Person)oldInstance).getLastName();
    return new Expression(
     oldInstance,
     PersonFactory.class,
     "createPerson",
     new Object[] {lastName});
  }
 }
);
e.writeObject(p);

Listing 2

XMLEncoder e = new XMLEncoder(os);
Person p = new Person();
p.addNickname("Jonny");
p.addNickname("Jonboy");
e.setPersistenceDelegate(Person.class,new DefaultPersistenceDelegate(){
  protected void initialize(Class type,Object oldInstance, Object 
  newInstance,Encoder out) {
   Person cst = (Person)oldInstance;
   Iterator iter = cst.getNicknames().iterator();
   while(iter.hasNext()){
     out.writeStatement(new Statement(
     oldInstance,
     "addNickname",
     new Object[] { iter.next() } ));
   }
  }
 });
e.writeObject(p);

Listing 3

<?xml version="1.0" encoding="UTF-8"?>
<java version="1.4.1" class="java.beans.XMLDecoder">
 <object class="Person">
  <void method="addNickname">
   <string>Jonny
  </void>
  <void method="addNickname">
   <string>Jonboy
  </void>
 </object>
</java>

Listing 4

public PropertyDescriptor[] getPropertyDescriptors() {
 PropertyDescriptor[] result = 
  new PropertyDescriptor[] {
   new PropertyDescriptor("firstName",Person.class),
   new PropertyDescriptor("lastName",Person.class)
 };
 result[0].setValue("transient",Boolean.TRUE);
 return result;
}