XStream是thoughtworks开发的开源产品,采用的是xpp来进行xml和对象之间的转换。 它不需要schema或其他的mapping文件就可以进行java对象和xml文件之间的转换,API调 用起来非常方便,并且扩展功能强大。
网址:http://xstream.codehaus.org
JSON是目前比较流行的轻量级的对象数据转换方式,常常用在ajax和web service领域 。目前大部分语言都有JSON的实现。Java领域有json lib,还有xstream json(jettison) 。
网址:http://json-lib.sourceforge.net/
http://jettison.codehaus.org
主要是对3者 (xstream, json lib, xstream json) 转换的数据长度,还有转换的效 率做个比较。
转换的java类为:
package com.ldd600.ws;
public class Employee {
private String name;
private int age;
private Address address;
private double salary;
private boolean isActive;
private char sexy;
public String getName() {
return name;
}
public void setName(String naem) {
this.name = naem;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public boolean isActive() {
return isActive;
}
public void setActive(boolean isActive) {
this.isActive = isActive;
}
public char getSexy() {
return sexy;
}
public void setSexy(char sexy) {
this.sexy = sexy;
}
}