Thoughtworks XStream介绍

Xsteam Intro

XStreamthoughtworks开发的开源产品,采用的是xpp来进行xml和对象之间的转换。它不需要schema或其他的mapping文件就可以进行java对象和xml文件之间的转换,API调用起来非常方便,并且扩展功能强大。Offical site: http://xstream.codehaus.org/index.html

 

官方介绍:XStream is a simple library to serialize objects to XML and back again.

Feature list:

Ø Ease of use. A high level facade is supplied that simplifies common use cases.

Ø 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 particular 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: 在配合JDK1.4或者1.3版本使用时,由于Xstream会任意根据Class实例化对象,所以会存在一些于老JVM安全框架上的冲突。

 

Demo to use:

首先只要编写一个POJO对象,而且这个对象甚至不需要getter/setter方法。同事对象的访问描述符是public还是private Xstream并不关心。

  

 

接下来,构造一个XStream实例(此类利用了Façade设计模式,所有的方法都是for common use),传递字定义的POJO class对象给XStream,之后使用该实例的toXMLfromXML就可以自由转换Java ObjectXML String了。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值