H'guys,
I was trying to serialize a hibernate 'person' object, that i retrieved from the database, into xml and this is the output i got.
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.6.0" class="java.beans.XMLDecoder">
<object class="events.Person$$EnhancerByCGLIB$$4e6330"/>
</java>
The code I am useg to serialize the java object is..
Person aPerson = (Person) session.load(Person.class, objId);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLEncoder encoder = new XMLEncoder(baos);
encoder.writeObject(aPerson);
encoder.close();
String oXML = baos.toString();
Now if I instanciate the patient object and then serialize it WITHOUT saving it in the database like this..
Person aPerson = new Person();
thePerson.setFirstname("firstname");
thePerson.setLastname("lastname");
this is what I get.
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.6.0" class="java.beans.XMLDecoder">
<object class="events.Person">
<void property="firstname">
<string>firstname</string>
</void>
<void property="lastname">
<string>lastname</string>
</void>
</object>
</java>
Now this is how i want the xml serialization of the object that i load from the database to look like but for some reason it doesn't work.
Any sort of help here will be highly appreciated. (Any other serialization technique will also do bacause all i want to be able to serialize a hibernate object which has be loaded from a database, into xml)
thanks,
pix.
|