Introduction to thoughtworks xstream

Source: Internet
Author: User

Xsteam intro

Xstream is an open-source product developed by thoughtworks. It uses xpp for conversion between XML and objects. It can be converted between Java objects and XML files without the need for schema or other Mapping Files. API calls are very convenient and powerful in expansion. Offical
Site: http://xstream.codehaus.org/index.html

 

Official introduction: xstream is a simple library to serialize objects to XML and back again.

Feature list:

Ø
Usage of use. A high level facade is supplied
That simplifies common use case.

Ø
No mappings required. Most objects can
Be serialized without need for specifying mappings.

Ø
Performance. speed and low memory footprint
Are a crucial part of the design, making it suitable for large object graphs or systems with high message throughput.

Ø
Clean XML. No information is duplicated
That can be obtained via reflection. This results in XML that is easier to read for humans and more compact than native Java serialization.

Ø
Requires no modifications to objects. serializes
Internal fields, including private and final. supports non-public and inner classes. Classes are not required to have default constructor.

Ø
Full object graph support. Duplicate
References encountered in the object-model will be maintained. Supports circular references.

Ø
Integrates with other XML APIs. By implementing
An interface, xstream can serialize directly to/from any tree structure (not just XML ).

Ø
Customizable conversion strategies. Strategies
Can be registered allowing customization of how particle types are represented as XML.

Ø
Error messages. When an exception occurs
Due to malformed XML, detailed diagnostics are provided to help isolate and fix the problem.

Ø
Alternative output format. The Modular
Design allows other output formats. xstream ships currently with JSON support and morphing.

 

Note:
When used in combination with JDK 1.3 or, xstream will instantiate Objects Based on class at will, so there will be some conflicts on the old JVM security framework.

 

Demo to use:

First, you only need to write a pojo object, and this object does not even need the getter/setter method. The access descriptor of the colleague object is public or private,
Xstream is not concerned.

Public class demo {<br/> private string strfield; <br/> private int intfield <br/> private double doublefield; </P> <p> // constructor or methods <br/>}< br/>

 

Next, construct an xstream instance (this class utilizes the fa c ade design pattern, and all the methods are
Common use), pass the pojo class object defined by the word to xstream, and then use toxml and fromxml of the instance to freely convert Java object and XML string.

Xstream = new xstream (); <br/> xstream. alias ("Demo", demo. class); </P> <p> demo instance = new demo (); <br/> instance. setstringfield ("ABC"); <br/> instance. setintfield (123); <br/> instance. setdoublefield (3.14); </P> <p> string xml = xstream. toxml (instance); <br/> demo fake = (DEMO) xtream. fromxml (XML );

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.