This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
fastjson有没有类似于jackson的类级别的JsonNaming注解,实现下划线驼峰(json property)和大小写驼峰(java jean property)转换? #1555
Labels
Milestone
Comments
lovepoem
changed the title
fastjson有没有类似于jackson的JsonNaming注解?
fastjson有没有类似于jackson的JsonNaming注解,实现下划线驼峰(json property)和大小写驼峰(java jean property)转换?
Oct 31, 2017
lovepoem
changed the title
fastjson有没有类似于jackson的JsonNaming注解,实现下划线驼峰(json property)和大小写驼峰(java jean property)转换?
fastjson有没有类似于jackson的类级别的JsonNaming注解,实现下划线驼峰(json property)和大小写驼峰(java jean property)转换?
Oct 31, 2017
目前看不满足,我想要一个注解,实现字段名转换的定制方便。 类名设置了转换策略: import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
public class Test {
public static void main(String[] args) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
Student student = new Student();
student.setStudentName("hahah");
student.setStudentAddress("123");
String json = mapper.writeValueAsString(student);
System.out.println(json);
}
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
static class Student {
private String studentName;
@JsonProperty("studentAddress")
private String studentAddress;
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public String getStudentAddress() {
return studentAddress;
}
public void setStudentAddress(String studentAddress) {
this.studentAddress = studentAddress;
}
}
} 执行结果为: {"student_name":"hahah","studentAddress":"123"} 反之也成立 |
wenshao
added a commit
that referenced
this issue
Nov 3, 2017
明白你的意思了,谢谢你这么好的建议,将会在周末发布新版本支持 |
太棒啦 |
wenshao
added a commit
that referenced
this issue
Jan 1, 2018
wenshao
added a commit
that referenced
this issue
Jul 17, 2019
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
fastjson有没有类似于jackson的JsonNaming注解?
jackson用法:
可以在类级别实现下划线驼峰(json property)和大小写驼峰转换(java jean property)?
eg: java property:studentName <---> json property: student_name
PropertyNamingStrategy.SnakeCase目前看只有全局config可以设定,并没有类级别的注解。
The text was updated successfully, but these errors were encountered: