HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML

"XML Serialization of Java Objects"
Vol. 8, Issue 6, p. 34


Listing 1

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

Listing 2

XMLEncoder e = new XMLEncoder(os);
Person p = new Person();
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();
     out.writeStatement(new Statement(
     new Object[] { iter.next() } ));

Listing 3

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

Listing 4

public PropertyDescriptor[] getPropertyDescriptors() {
 PropertyDescriptor[] result = 
  new PropertyDescriptor[] {
   new PropertyDescriptor("firstName",Person.class),
   new PropertyDescriptor("lastName",Person.class)
 return result;


All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: info@sys-con.com

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.