XmlSerialization: Serialize objects


Sunday, August 23, 2020 Difficulty: Intermediate

Objective

Create a Java program to serialize and deserialize objects in XML format. To do this you can use the XmlSerialization class included in the System.Xml.Serialization namespace.

First implement a Person class with three properties (Name, Age and City). The City class will have two properties (Name and Population). Then create a person object and use the XmlSerialization object serializer to save the data in an xml file, later deserialize the file and print it on screen. Remember to prepare a ToString() method to print the Persona class.

Input


                    

Output


                    

Solution

Click here to view the exercise solution

Share it

Share it on your social media and challenge your friends to solve programming problems. Together, we can learn and grow.

Copied

The code has been successfully copied to the clipboard.

More Exercises

Continue improving your Java programming skills with our selection of practical exercises from the lesson. Click on Practice and challenge your knowledge!

1

BinaryFormatter: Binary serialization

Create a Java program to serialize and deserialize objects in binary format.

2

XmlSerialization: Serialize objects

Create a Java program to serialize and deserialize objects in XML format.

3

JavaScriptSerializer: Serialize objects

Create a Java program that serialize and deserialize objects in JSON format.

4

DataContractJsonSerializer: Serialize objects

Create a Java program that serialize and deserialize objects in JSON format.

5

Newtonsoft.Json: Serialize objects

Create a Java program to serialize and deserialize objects in JSON format.

Data serialization

Practice with exercises in Java to serialize arrays or objects in different ways. Learn how to serialize and deserialize the information later.

Practice exercises

Keep learning

C# Programming Course

Free programming course with practical exercises and solutions in C#. Start learning right now!

Exercises C# App

Take your Exercises C# lessons everywhere with our Android app. Download it now from Google Play