Java technology

Java technology

xstream object streams

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.useAttributeFor(Student.class, “studentName”); xstream.aliasField(“name”, Student.class, “studentName”); xstream.addImplicitCollection(Student.class, “notes”); The following code snippet illustrates the use of annotations to do the same work in a much easier way. @XStreamAlias(“student”) //define class level […]

Read More
Java technology

xstream writing json using xstream

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. Using Converter Let us use a SingleValueConvertor whose purpose is to convert an object into a single […]

Read More
Java technology

xstream quick guide

XStream provides alternative implementations of java.io.ObjectInputStream and java.io.ObjectOutputStream so that streams of objects can be serialized or deserialized from XML. This is particularly useful when large sets of objects are to be processed, keeping one object in memory at a time. Syntax: createObjectOutputStream() ObjectOutputStream objectOutputStream = xstream.createObjectOutputStream( new FileOutputStream(“test.txt”)); Syntax: createObjectInputStream() ObjectInputStream objectInputStream = xstream.createObjectInputStream( […]

Read More
Java technology

xstream useful resources

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. Create a java class file named XStreamTester in C:\>XStream_WORKSPACE\com\tutorialspoint\xstream. File: XStreamTester.java package com.tutorialspoint.xstream; import java.io.Writer; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.annotations.XStreamAlias; import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver; import com.thoughtworks.xstream.io.json.JsonWriter; public class […]

Read More
Java technology

discuss xstream

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. Performance − […]

Read More
Java technology

xstream environment setup

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 features of XStream library and how to use them. Table of Contents 1.xstream tutorial 2.xstream overview 3.xstream environment setup 4.xstream first application 5.xstream aliasing […]

Read More
Java technology

xstream first application

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. Performance − XStream is fast […]

Read More
Java technology

xstream aliasing

In this chapter, we will discuss on the different aspects of setting up a congenial environment for Java. Local Environment Setup If you want to set up your environment for Java programming language, then this section explains how to download and set up Java on your machine. Please follow the steps given below to set […]

Read More
Java technology

xstream annotations

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. Create a java class […]

Read More
Java technology

xstream converters

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”> <note> <title>first</title> <description>My first assignment.</description> </note> <note> <title>second</title> <description>My second assignment.</description> </note> </student> Based on the above XML […]

Read More