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

首字母序列化问题[QUESTION] #2589

Open
Mtczf opened this issue May 17, 2024 · 2 comments
Open

首字母序列化问题[QUESTION] #2589

Mtczf opened this issue May 17, 2024 · 2 comments
Labels
question Further information is requested

Comments

@Mtczf
Copy link

Mtczf commented May 17, 2024

询问有关本项目的使用和其他方面的相关问题。

问题描述

老项目中有些bean字段命名不规范,有些字段名首字母大写,在fastjson 1.x版本中会生成首字母大写和首字母小写两个字段,在fastjson2.x版本中则只生成首字母小写字段,请问下在fastjson2.x版本有什么方法可以保持一致

重现步骤

public class JsonTest {
    public String JsonName;

    public String getJsonName() {
        return JsonName;
    }

    public void setJsonName(String jsonName) {
        JsonName = jsonName;
    }

    public static void main(String[] args) {
        JsonTest jsonTest = new JsonTest();
        jsonTest.setJsonName("test");
        String jsonString = JSONObject.toJSONString(jsonTest);
        System.out.println(jsonString);
    }
}

打印结果

fastjson 1.2.83:
TOaFTzQjO4
c3LnifQT4y

fastjson 2.0.48:
1ceNIlgGfz

@Mtczf Mtczf added the question Further information is requested label May 17, 2024
@wenshao
Copy link
Member

wenshao commented May 17, 2024

fastjson 2.x的行为更合理啊

@Mtczf
Copy link
Author

Mtczf commented May 20, 2024

是的,fastjson2.x更规范,主要是历史遗留问题,涉及的地方有太多...所以想了解下,除了使用@JSONField注解解决,fastjson2.x有提供其他方法可以改造解决吗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants