alibaba / alibaba/fastjson2

[QUESTION]如何让部分的字段使用驼峰命名,其他字段使用蛇形命名呢?

Open
#1,265 1 comment 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

比如实体类:
```java
@Data
public class SnakeUserInfo{
private String username;
private String userPhone;

private CamelUserInfo camelInfo;

@Data
public static class CamelUserInfo{
private String camelUsername;
private String camelUserPhone;
}

private String password;
//etc...
}
```
我想让`CamelUserInfo`类下的所有字段保持自己的命名风格(驼峰),而其他的字段都变成蛇形(有很多字段)
预期的json如下
```json
{
"username": "xxxx",
"user_phone": "123456789",
"camel_info": {
"camelUsername": "xxxx",
"camelUserPhone": "123456789"
},
"password": "123"
}
```

也就是说对于默认的字段,我想用蛇形,但有特殊的一些字段,我想用驼峰。
但因为字段过多,用`@JsonField`有点太乱了。
有无好方法?

Contributor guide

Open the contributing guide

Research direction

The issue names no source files, tests, or entry points. Start by clarifying the intended configuration or annotation approach for mixed naming strategies, then trace the existing Java serialization configuration. Done means producing the shown JSON shape while keeping the nested CamelUserInfo fields camelCase and other fields snake_case.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.