alibaba / alibaba/fastjson2

首字母序列化问题[QUESTION]

Open
#2,589 2 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Java
Stars
4.4k
Forks
613
Avg merge
1d 22h
Merged PRs (30d)
6

Description

*询问有关本项目的使用和其他方面的相关问题。*
### 问题描述
老项目中有些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](https://github.com/alibaba/fastjson2/assets/17916230/0c355257-b3eb-48d7-822a-304268e29009)
![c3LnifQT4y](https://github.com/alibaba/fastjson2/assets/17916230/dbf48189-7b3f-4ef4-84b6-4aa4de4ccee4)

**fastjson 2.0.48:**
![1ceNIlgGfz](https://github.com/alibaba/fastjson2/assets/17916230/b4118406-e45c-41cb-a2e8-534f131ba550)

Contributor guide

Open the contributing guide

Research direction

Start with the supplied JsonTest reproduction and compare the serialized output in fastjson 1.2.83 and 2.0.48. Investigate how the differing handling of the JsonName field is configured or implemented, then verify whether fastjson2 can preserve the earlier field-name behavior and document the resulting supported approach.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.