Skip to content
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] json字符串中的需要反序列化字段是个对象,但是传入值为空字符时候解析出错 #998

Closed
mystox opened this issue Dec 7, 2022 · 3 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@mystox
Copy link

mystox commented Dec 7, 2022

问题描述

json字符串中的需要反序列化字段是个对象,但是传入值为空字符时候解析出错

环境信息

  • 版本信息:[e.g.:Fastjson2 2.0.20]

重现步骤

{"cloudServiceName":"xxx","enterpriseCode":"xxx","enterpriseName":"xxx","serviceCode":"IT_MONITOR_MANAGER_SYSTEM","cloudStyle":""}

public class EnterpriseCloudServiceVO {

    private String enterpriseCode;
    private String enterpriseName;
    private String serviceCode;
    private String cloudServiceName;
    private CloudStyle cloudStyle;
    ...省略getter setter
}
public class CloudStyle implements Serializable {
    private Integer modelId;
    public Integer getModelId() {
        return modelId;
    }
    public void setModelId(Integer modelId) {
        this.modelId = modelId;
    }
}
    public static void main(String[] args) {
         String str = "{\"cloudServiceName\":\"xxx\",\"enterpriseCode\":\"xxx\",\"enterpriseName\":\"xxx\",\"serviceCode\":\"IT_MONITOR_MANAGER_SYSTEM\",\"cloudStyle\":\"\"}";
        EnterpriseCloudServiceVO enterpriseCloudServiceVO = JSONObject.parseObject(str, EnterpriseCloudServiceVO.class);
    }

期待的正确结果

正确解析

相关日志输出

Exception in thread "main" com.alibaba.fastjson2.JSONException: expect ':', but }, offset 128, character ", line 1, column 129, fastjson-version 2.0.20 {"cloudServiceName":"xxx","enterpriseCode":"xxx","enterpriseName":"xxx","serviceCode":"IT_MONITOR_MANAGER_SYSTEM","cloudStyle":""}
at com.alibaba.fastjson2.JSONReaderUTF16.readFieldNameHashCode(JSONReaderUTF16.java:1312)
at com.alibaba.fastjson2.reader.ObjectReader_2.readObject(Unknown Source)
at com.alibaba.fastjson2.reader.ObjectReader_1.readObject(Unknown Source)
at com.alibaba.fastjson2.JSON.parseObject(JSON.java:807)
at com.alibaba.fastjson2.JSONObject.parseObject(JSONObject.java:1859)
at com.itime.center.manage.model.vo.EnterpriseCloudServiceVO.main(EnterpriseCloudServiceVO.java:34)

附加信息

@mystox mystox added the bug Something isn't working label Dec 7, 2022
@wenshao wenshao added this to the 2.0.21 milestone Dec 9, 2022
@wenshao wenshao added the fixed label Dec 10, 2022
@wenshao
Copy link
Member

wenshao commented Dec 10, 2022

https://github.com/alibaba/fastjson2/releases/tag/2.0.21
问题已修复,请用新版本

@wenshao wenshao closed this as completed Dec 10, 2022
@TanZhiL
Copy link

TanZhiL commented Apr 1, 2023

cloudStyle

@mystox 你的问题修复了吗?

@TanZhiL
Copy link

TanZhiL commented Apr 3, 2023

当处理的字段类型内部带有一个以上的字段时,还是不行哦,比如:
public class CloudStyle implements Serializable {
private Integer modelId;
private Integer modelId1;
public Integer getModelId() {
return modelId;
}
public void setModelId(Integer modelId) {
this.modelId = modelId;
}

public Integer getModelId1() {
    return modelId1;
}

public void setModelId1(Integer modelId1) {
    this.modelId1 = modelId1;
}

}
@wenshao

https://github.com/alibaba/fastjson2/releases/tag/2.0.21 问题已修复,请用新版本

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

3 participants