Showing posts with label XStream Tutorial. Show all posts
Showing posts with label XStream Tutorial. Show all posts

Wednesday, January 25, 2017

XStream - Overview

XStream is a simple Java-based library to serialize Java objects to XML and vice versa.

Features

  • Easy to use - XStream API provides a high-level facade to simplify common use cases.
  • No need to create mapping - XStream API provides default mapping for most of the objects to be serialized.

XStream - Environment Setup

Try it Option Online

We already have set up Java Programming environment online, so that you can compile and execute all the available examples at the same time when you are doing your theory work. This gives you confidence in what you are reading and to check the result with different options. Feel free to modify any example and execute it online.

XStream - First Application

Before going into the details of the XStream library, let us see an application in action. In this example, we've created Student and Address classes. We will create a student object and then serialize it to an XML String. Then de-serialize the same XML string to obtain the student object back.

XStream - Aliasing

Aliasing is a technique to customize the generated XML or to use a particular formatted XML using XStream. Let's suppose, the following XML format is to be used to serialize/de-serialize the Student object.
<student name="Suresh">

XStream - Annotations

XStream supports annotations similarly like automatic configuration instead of coding. In the previous chapter, we've seen the following configurations in code.
xstream.alias("student", Student.class);
xstream.alias("note", Note.class);

XStream - Converters

XStream converters are the key components of the XStream library, which are responsible to convert an object to XML and vice versa. XStream provides numerous converters for common types such as primitives, String, File, Collections, arrays, and Dates.

XStream - Object Streams

XStream provides alternative implementations of java.io.ObjectInputStream and java.io.ObjectOutputStream so that streams of objects can be serialized or de-serialized from XML. This is particularly useful when large sets of objects are to be processed, keeping one object in memory at a time.

XStream - Writing JSON using XStream

XStream supports JSON by initializing XStream object with an appropriate driver. XStream currently supports JettisonMappedXmlDriver and JsonHierarchicalStreamDriver.
Let us now test the code with json handling in XStream.

XStream - Quick Guide

XStream - Overview

XStream is a simple Java-based library to serialize Java objects to XML and vice versa.

Features

  • Easy to use - XStream API provides a high-level facade to simplify common use cases.
  • No need to create mapping - XStream API provides default mapping for most of the objects to be serialized.

XStream - Useful Resources

The following resources contain additional information on XStream. Please use them to get more in-depth knowledge on this topic.

Discuss XStream

XStream is a simple Java-based library to serialize Java objects to XML and vice versa. This is a brief tutorial that adopts a simple and intuitive way to explain the basic feature of XStream library and how to use them.