-
Notifications
You must be signed in to change notification settings - Fork 511
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[BUG]大写单字母名称字段序列化与反序列化错误 #924
Comments
https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.19-SNAPSHOT/ |
经过测试,对象序列化为字符串是正确的。但通过字符串{"c": 100}反序列化对象时,对象的C字段仍然可以保存为100。 我认为反序列化后的C字段应该是null,因为C和c大小写不一致。 重现步骤public class Main {
public static void main(String[] args) {
System.out.println(JSON.parseObject("{\"c\":100}", Entity.class));
}
public static class Entity {
private Long C;
public Entity(Long c) {
C = c;
}
public Entity() {
}
public Long getC() {
return C;
}
public void setC(Long c) {
C = c;
}
@Override
public String toString() {
return "Entity{" +
"C=" + C +
'}';
}
}
} 期望结果Entity{C=null} 实际结果Entity{C=100} |
反序列化这个场景需要自动识别"c"和"C",要不然会有升级兼容问题 |
问题描述
对包含大写单字母名称的字段进行序列化与反序列化时错误
环境信息
重现步骤
期待正确结果
Main.Entity(C=100)
{"C":100}
Main.Entity(C=100)
实际输出结果
Main.Entity(C=100)
{"c":100}
Main.Entity(C=100)
附加信息
第二行代码应该被序列化为{"C":100}。但实际上被序列化为{"c":100}。而通过{"c":100}去反序列化Entity时,正确的结果应该是Main.Entity(C=null)。
The text was updated successfully, but these errors were encountered: