Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

布尔值序列化问题 #2795

Closed
luoxc007 opened this issue Jul 10, 2024 · 2 comments
Closed

布尔值序列化问题 #2795

luoxc007 opened this issue Jul 10, 2024 · 2 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@luoxc007
Copy link

问题描述

Fastjson2对布尔值序列化的问题

环境信息

Fastjson 2.0.51

重现步骤

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Builder;
import lombok.Data;
import org.junit.Test

public class FastJSONTest {

    @Builder
    @Data
    public static class Student{
        @JSONField(name= "is_judge")
        private boolean isJudge;
    }

    @Test
    public void testFastJson(){
        Student student = Student.builder().isJudge(true).build();
        System.out.println(JSONObject.toJSONString(student));
    }
}

期待的正确结果

输出的结果可以发现isJudge字段变成了judge,这个是和1版本不一致的,我试过1.2.83是可以转成is_judge的。使用@DaTa会为isJudge字段生成一个getter,就叫isJudge(),方法和字段同名,可能这里就是导致判断逻辑不一致的原因。我想请问这里是bug还是预期之内?

相关日志输出

{"judge":true}

附加信息

@luoxc007 luoxc007 added the bug Something isn't working label Jul 10, 2024
@wenshao wenshao added this to the 2.0.52 milestone Jul 13, 2024
@wenshao wenshao added the fixed label Jul 13, 2024
@wenshao
Copy link
Member

wenshao commented Jul 14, 2024

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

@wenshao wenshao closed this as completed Jul 14, 2024
@luoxc007
Copy link
Author

谢谢,辛苦了!

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

No branches or pull requests

2 participants