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

Closed
yaozhihang opened this issue Mar 20, 2024 · 3 comments
Closed
Assignees
Labels
bug Something isn't working fixed
Milestone

Comments

@yaozhihang
Copy link

问题描述

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

环境信息

请填写以下信息:

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

重现步骤

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

第一步定义测试类

public class TestClass {
    @JSONField(deserializeFeatures = { JSONReader.Feature.FieldBased })
    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 20, 2024
@yanxutao89 yanxutao89 self-assigned this Mar 21, 2024
wenshao pushed a commit that referenced this issue Mar 21, 2024
* fix support FieldBased feature on field for issue #2350

* fix support FieldBased feature on field for issue #2350

* fix checkstyle
@wenshao
Copy link
Member

wenshao commented Mar 21, 2024

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.48-SNAPSHOT/ 问题已修复,请帮忙用2.0.48-SNAPSHOT验证,2.0.48正式版本预计在月末发布

@wenshao wenshao added the fixed label Mar 21, 2024
@wenshao wenshao added this to the 2.0.48 milestone Mar 21, 2024
@yaozhihang
Copy link
Author

非常感谢! 问题修复已验证。

@wenshao
Copy link
Member

wenshao commented Mar 25, 2024

@wenshao wenshao closed this as completed Mar 25, 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