首页 > 编程语言 >fastJson将json对象转为java对象,属性名不同的映射(@JSONField)

fastJson将json对象转为java对象,属性名不同的映射(@JSONField)

时间:2022-09-06 10:13:45浏览次数:101  
标签:fastJson count java 映射 json JSONField 属性

JSONObject.toJavaObject(JSON json,Class<T> clazz);  

功能:1.将json转为java对象

   2.json中下划线格式自动映射到java属性中驼峰格式‘

   3.如果json中的字段和要映射的java属性名不同,可以在java类要映射的属性的set方法上添加@JSONField注解’,如下可以把json中“peer_count”字段值映射到java中“count”属性上。

@JSONField(name = "peer_count")
public void setCount(String count) {
this.count = count;
}

 

标签:fastJson,count,java,映射,json,JSONField,属性
From: https://www.cnblogs.com/sfnz/p/16660772.html

相关文章