-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Serializing a hibernate java object into xml
PostPosted: Wed Mar 07, 2007 9:17 am 
Newbie

Joined: Tue Feb 20, 2007 6:54 am
Posts: 7
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.