java的json解析类库使用示例

时间:2021-11-01 10:02:49

开源项目主页: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);
  }