Understanding XML serialization of Java objects

For serializing a Java object into XML, you can use an open source Java library called XStream. For using this library you have to download and install it and then use the following import statement in your Java code.

import com.thoughtworks.xstream.XStream;

Once you have included this class in your code, you can create an XStream object and then use that object to serialize any class you want. To create an xstream object you will be writing code like,

XStream xstrm = new XStream();

Suppose you have a class called 'car' with the member variables like 'model' and 'make' which is written as given below.

class car {
string model;
string make;
}

You can serialize this class using the following code,

String xml = xstrm.toXML(car);

Now use a print statement to print the values of the string xml. You can also deserialize the XML to Java objects. Sample code for these conversions is available in the internet.



.

SetApp - 100 Apps for everything you ever wanted to do on Mac

FREE Subscription

Subscribe to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.

Name:
Email:

Note : We never rent, trade, or sell my email lists to
anyone. We assure that your privacy is respected
and protected.

_______________________________________



 

 

FREE Subscription

Stay Current With the Latest Technology Developments Realted to XML. Signup for Our Newsletter and Receive New Articles Through Email.

Name:

Email:

Note : We never rent, trade, or sell our email lists to anyone. We assure that your privacy is respected and protected.

 

 

Add to My Yahoo!

Visit XML Training Material Guide Homepage

 

 

“Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.”

Copyright - © 2004 - 2019 - All Rights Reserved.