alibaba / fastjson

FASTJSON 2.0.x has been released, faster and more secure, recommend you upgrade.
https://github.com/alibaba/fastjson2/wiki/fastjson_1_upgrade_cn
Apache License 2.0
25.74k stars 6.5k forks source link

结合JsonCreator,构造参数通过JSONField定义与原成员不同类型时,反序列化失败。 #1879

Open deqingLv opened 6 years ago

deqingLv commented 6 years ago

在bug fix #1458,之后出现的问题。

image

在解析完JsonCreator之后,这里通过注释,不返回JsonBean,走到后面的method的逻辑,会添加新的filed。这里会存在filed的冲突,通过compareTo没能很好的解决冲突,导致反序列化失败。

引发问题的代码:

@ToString
@Getter
@Setter
class Test {
     private List<Long> ids;

     @JSONCreator
     public Test(@JSONField(name = ids) String ids) {
            ids = new ArrayList();
            for(String id : ids.split(",")) {
                  ids.add(Long.valueOf(id));
            }
     }
}

序列化字符串:

{
   "ids" : "1,2,3"
}

由于JSONField定义的类型:String与成员变量的类型 List冲突, 最终反序列化时,会将ids当作List数组去解析,导致反序列化失败

wenshao commented 6 years ago

什么版本?

deqingLv commented 6 years ago

原版本1.2.32是没有问题的,更新到1.2.48发现的问题