@XStreamAlias use
First, Features:
Simplified API;
no mapping file;
High performance, low memory footprint;
Neat XML;
No need to modify objects; Support internal private fields, no Setter/getter method required
provides a serialization interface;
Custom conversion type policy;
Second, the use of the scene
Transport conversion
Persistence persisted objects
Configuration configurations
Unit Tests Units Test
interface interaction of XML messages between services
Case code:
@XStreamAlias ("Kfpt_dept")classDept {PrivateString Deptname; PrivateList<staff>staffs; PublicString Getdeptname () {returnDeptname; } Public voidsetdeptname (String deptname) { This. Deptname =Deptname; } PublicList<staff>getstaffs () {returnstaffs; } Public voidSetstaffs (list<staff>staffs) { This. Staffs =staffs; } @Override PublicString toString () {returnTostringbuilder.reflectiontostring ( This, Tostringstyle.multi_line_style); }} @XStreamAlias ("Kfpt_staffs")classStaff {PrivateString name; Private intAge ; PublicStaff () {Super(); } PublicStaff (String name,intAge ) { Super(); This. Name =name; This. Age =Age ; } PublicString GetName () {returnname; } Public voidsetName (String name) { This. Name =name; } Public intGetage () {returnAge ; } Public voidSetage (intAge ) { This. Age =Age ; } @Override PublicString toString () {returnTostringbuilder.reflectiontostring ( This, Tostringstyle.multi_line_style); }}
Conversion Tool Classes:
Public classXstreamutil {/*** Convert bean to XML *@paramobj-Converted Bean *@returnBean conversion to XML*/ Public StaticString objecttoxml (Object obj) {XStream XStream=NewXStream (); //xstream using annotation transformationsxstream.processannotations (Obj.getclass ()); returnxstream.toxml (obj); } /*** Convert XML to Bean *@param<T> Generics *@paramXML to be converted to bean XML *@paramCLS Bean corresponding class *@returnconvert XML to Bean*/ Public Static<T> T xmltoobject (String XML, class<t>CLS) {XStream XStream=NewXStream (Newdomdriver ()); //xstream using annotation transformationsxstream.processannotations (CLS); return(T) xstream.fromxml (XML); }}
Cond.............
XML and Java Object Transformation--Xstreamalias