開源項目主頁:https://github.com/dongfangshangren/Zson
代碼如下:
import java.util.List;
import java.util.ArrayList;
import java.lang.reflect.Type;
import org.zson.JsonSerializer;
import org.zson.TypeReference;
import org.zson.JsonDeserializer;
import test.bean.SomeBean;
public class TestZson{
public static void main(){
//Serialize
List<SomeBean> list=new ArrayList<SomeBean>();
String json=new JsonSerializer().prettyFormat(2).ignoreNull(false)
.dateFormat("yyyy-MM-dd").serialize(list);
//Deserilize
Type type=new TypeReference<List<SomeBean>>(){}.getType();
List<SomeBean> result=(List<SomeBean>)new JsonDeserializer().deserialize(json,type);
}
}