当前位置:网站首页>Difference between @JsonProperty and JSONField?
Difference between @JsonProperty and JSONField?
2022-08-03 06:12:00 【Shiyu】
Purpose: It is all to solve the problem that some attribute names in the json string do not match the attribute names in JavaBean.
1.JsonProperty is located in the jackson package and used with the ObjectMapper().writeValueAsString(entity class) method to convert the entity class into a string.
Use with the ObjectMapper().readValue(string) method to convert the string into an entity class.
com.fasterxml.jackson.core jackson-databind version number Test example:
Entity class: User.java
import com.fasterxml.jackson.annotation.JsonProperty;public class User {@JsonProperty("JsonPropertyName")private String name;private String sex;private Integer age;public String getName() {return name;}public void setName(String name) {this.name = name;}public String getSex() {return sex;}public void setSex(String sex) {this.sex = sex;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age = age;}public User(String name, String sex, Integer age) {super();this.name = name;this.sex = sex;this.age = age;}public User() {super();}@Overridepublic String toString() {return "User [name=" + name + ", sex=" + sex + ", age=" + age + "]";}}Test method:
@Testpublic void testJsonProperty() throws IOException{User user=new User("shiyu","man",22);System.out.println(new ObjectMapper().writeValueAsString(user));String str="{\"sex\":\"man\",\"age\":22,\"JsonPropertyName\":\"shiyu\"}";System.out.println(new ObjectMapper().readValue(str, User.class).toString());}Output result:
{"sex":"man","age":22,"JsonPropertyName":"shiyu"}User [name=shiyu, sex=man, age=22]2.JSONField is located in the fastjson package and used with the JSON.toJSONString (entity class) method to convert the entity class into a json string.Use with the JSON.parseObject(string, entity class. class) method to convert the string into an entity class.
com.alibaba fastjson version number Test example:
Entity class: User.java
import com.alibaba.fastjson.annotation.JSONField;public class User {@JSONField(name="JSONFieldName")private String name;private String sex;private Integer age;public String getName() {return name;}public void setName(String name) {this.name = name;}public String getSex() {return sex;}public void setSex(String sex) {this.sex = sex;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age = age;}public User(String name, String sex, Integer age) {super();this.name = name;this.sex = sex;this.age = age;}public User() {super();}@Overridepublic String toString() {return "User [name=" + name + ", sex=" + sex + ", age=" + age + "]";}}Test method:
@Testpublic void testSONField(){User user=new User("shiyu","man",22);System.out.println(JSON.toJSONString(user));String str="{\"JSONFieldName\":\"shiyu\",\"age\":22,\"sex\":\"man\"}";System.out.println(JSON.parseObject(str, User.class).toString());}Output result:
{"JSONFieldName":"shiyu","age":22,"sex":"man"}User [name=shiyu, sex=man, age=22]边栏推荐
- 003_旭日X3派初探:利用无线串口通信控制舵机
- 电子元器件之电子变压器可分为哪几类?
- 自监督论文阅读笔记 Self-supervised Learning in Remote Sensing: A Review
- 使用JSP实现简单的登录注册功能,并且使用Session跟踪用户登录信息
- 常见的电容器有哪些?唯样商城
- 微信小程序 自定义tabBar
- 二、Exception和Error有什么区别?
- 三、final、finally、 finalize有什么不同?
- ZEMAX | 探究 OpticStudio 偏振分析功能
- 自监督论文阅读笔记Index Your Position: A Novel Self-Supervised Learning Method for Remote Sensing Images Sema
猜你喜欢

自监督论文阅读笔记Index Your Position: A Novel Self-Supervised Learning Method for Remote Sensing Images Sema

深度学习基本概念

借助ginput函数在figure窗口实时读取、展示多条曲线的坐标值

神经网络之感知机

VS2022 encapsulation under Windows dynamic library and dynamic library calls

MySql的Sql语句的练习(试试你能写出来几道呢)

block底层探索

交叉熵(第六周)

电子元器件和电子元件的区别有那些?

window下VS2022封装动态库以及调用动态库
随机推荐
ZEMAX | 在设计抬头显示器(HUD)时需要使用哪些工具?
6. What is the difference between Vector, ArrayList and LinkedList?(design, performance, safety)
自监督论文阅读笔记 Incremental-DETR:Incremental Few-Shot Object Detection via Self-Supervised Learning
cb板上常用的电子元器件都有哪些?
IPC 通信 - IPC
window下VS2022封装静态库以及调用静态库
电子元器件之电子变压器可分为哪几类?
【第四周】MobileNet和HybridSN
BurpSuite 进阶玩法
2021-04-23
ZEMAX | 如何使用渐晕系数
STM32启动文件的选择
softmax和最大熵
动漫 吞噬星空
A.1#【内存管理】——1.1.1 node:struct pglist_data
Makefile
深度学习理论课程第八、九、十章总结
block底层探索
九、请介绍类加载过程,什么是双亲委派模型?
MCU接收串口字符型数据转换成数据型数据