Fastjson: 对于内部包含map的类, JSON 序列化出来的json, 没法parse回来..

Created on 26 May 2017  ·  1Comment  ·  Source: alibaba/fastjson

 @Test
  public void a(){
    A a = new A();
    String s = JSON.toJSONString(a);
    System.out.println(s);
    try {
      A a1 = JSON.parseObject(s, A.class);
    }catch (Exception e){
      e.printStackTrace();
    }
    A a1 = new Gson().fromJson(s, A.class);
    System.out.println(a1);
  }

  class A{
    public Map<String, Object> getA() {
      return a;
    }
    public void setA(Map<String, Object> a) {
      this.a = a;
    }
    Map<String, Object> a = new HashMap<>();  

按照上面的类, 可以用 fastjson序列化, 反序列化会报错.
gson可以处理成功.

question

Most helpful comment

case跟map无关,A上加statis即可

>All comments

case跟map无关,A上加statis即可

Was this page helpful?
0 / 5 - 0 ratings