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] 在@JSONType下配置了 JSONReader.Feature.FieldBased 无效 #2371

Closed
yaozhihang opened this issue Mar 26, 2024 · 1 comment
Closed
Labels
bug Something isn't working fixed
Milestone

Comments

@yaozhihang
Copy link

问题描述

@JSONType 下配置了 JSONReader.Feature.FieldBased, 反序列化后priate字段依然是NULL。

环境信息

请填写以下信息:

  • OS信息: Windows 10
  • JDK信息: Openjdk 17
  • 版本信息:2.0.48

重现步骤

如何操作可以重现该问题:

第一步定义测试类

@JSONType(deserializeFeatures = {JSONReader.Feature.FieldBased})
public class TestClass {
    private String testField;

    public String getTestField() {
        return testField;
    }
}

第二步建立一个简单的JSON文件testConfig.json

{
	"testField": "My Test"
}

第三部写个main函数测试

public class test {
    public static void main(String[] args) throws Exception {
        TestClass test;
        try (InputStream stream = new BufferedInputStream(Files.newInputStream(Paths.get("testConfig.json")))) {
            test = JSON.parseObject(new String(stream.readAllBytes(), StandardCharsets.UTF_8), TestClass.class);
        }
        System.out.println(test.getTestField());
    }
}

期待的正确结果

输出结果是null. 而期待的结果应当是My Test.

@yaozhihang yaozhihang added the bug Something isn't working label Mar 26, 2024
@yanxutao89 yanxutao89 assigned yanxutao89 and unassigned yanxutao89 Mar 29, 2024
@wenshao wenshao modified the milestones: 2.0.50, 2.0.49 Apr 14, 2024
@wenshao wenshao added the fixed label Apr 14, 2024
@wenshao
Copy link
Member

wenshao commented Apr 14, 2024

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

@wenshao wenshao closed this as completed Apr 14, 2024
# 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