alibaba / alibaba/fastjson2

[FEATURE]

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

Description

### 请描述您的需求或者改进建议
目前只有实体类才能修改序列化从驼峰到下划线
能将 map , jsonObject 这两个类数据序列化的时候可以从驼峰改成下划线吗?
如:
``` java
JSONObject` child = new JSONObject();
child.put("testAData1", "1");
child.put("testAData2", "1");
child.put("testAData3", "1");
JSONObject mast = new JSONObject();
mast.put("aTest", "1");
mast.put("bTest", "1");
mast.put("cTest", "1");
mast.put("items", child);

JSONWriter.Context context = new JSONWriter.Context(new ObjectWriterProvider(PropertyNamingStrategy.SnakeCase));
String s = JSON.toJSONString(mast, context);
// 生成的:json数据
{
"aTest": "1",
"bTest": "1",
"cTest": "1",
"items": {
"testAData1": "1",
"testAData2": "1",
"testAData3": "1"
}
}
//期望生成的:json数据
{
"a_test": "1",
"b_test": "1",
"c_test": "1",
"items": {
"test_a_data1": "1",
"test_a_data2": "1",
"test_a_data3": "1"
}
}
```

### 请描述你建议的实现方案

### 描述您考虑过的替代方案
*对您考虑过的任何替代解决方案或功能的描述。*

Contributor guide

Open the contributing guide

Research direction

Start from JSONWriter.Context, ObjectWriterProvider, and PropertyNamingStrategy.SnakeCase shown in the example, then trace serialization for Map and JSONObject values. Done means nested map and JSONObject keys are converted from camelCase to snake_case, including the demonstrated output, without changing entity serialization.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.