1
复现代码:
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONType;
import com.alibaba.fastjson.serializer.SerializerFeature;
public class Main {
@JSONType(typeKey = "type",seeAlso = {A.class})
public static interface Base{}
@JSONType(typeKey = "type", typeName = "A", serialzeFeatures = SerializerFeature.WriteClassName)
public static class A implements Base {
int val;
public A(int val) {
this.val = val;
}
public void setVal(int val) {
this.val = val;
}
public int getVal() {
return val;
}
}
public static void main(String[] args) {
Base base = JSONObject.parseObject("{\"val\":1,\"type\":\"A\"}", Base.class);
System.out.println(base);
}
}
反序列化结果为null,显然是错误的,JSON对字段顺序不做要求。如果type是第一个则正常。 2.0.18中仍存在该问题。