fastjson icon indicating copy to clipboard operation
fastjson copied to clipboard

序列化和反序列号Class类型的字段时报错

Open ghost opened this issue 12 years ago • 3 comments

默认配置,自己试试就知道了。

ghost avatar Jul 07 '14 13:07 ghost

你说报错的是这个场景吗?下面的测试是没有问题的 public void test_1() throws Exception { VO v = new VO(); v.setC(String.class);

    String json = JSON.toJSONString(v);
    System.out.println(json);

    VO v1 = JSON.parseObject(json, VO.class);
    System.out.println(v1.getC());
}

public static class VO {

    private Class<String> c;

    public Class<String> getC() {
        return c;
    }

    public void setC(Class<String> c) {
        this.c = c;
    }
}

yakolee avatar Jul 28 '14 07:07 yakolee

最新版本貌似没问题了,试试38或者39版本。

2014-07-28 15:09 GMT+08:00 Yako [email protected]:

你说报错的是这个场景吗?下面的测试是没有问题的 public void test_1() throws Exception { VO v = new VO(); v.setC(String.class);

String json = JSON.toJSONString(v);
System.out.println(json);

VO v1 = JSON.parseObject(json, VO.class);
System.out.println(v1.getC());

}

public static class VO {

private Class<String> c;

public Class<String> getC() {
    return c;
}

public void setC(Class<String> c) {
    this.c = c;
}

}

— Reply to this email directly or view it on GitHub https://github.com/alibaba/fastjson/issues/195#issuecomment-50306396.

ghost avatar Jul 28 '14 07:07 ghost

ok,那应该就是已经修复了

yakolee avatar Jul 28 '14 07:07 yakolee