当前位置:网站首页>JSON serialization case summary
JSON serialization case summary
2022-07-03 13:24:00 【Vogat meets grapefruit】
json Case summary during serialization
1、 @JsonSerialize
@JsonSerialize@JsonSerialize annotation , Mainly used in data conversion , The annotation acts on the of the attribute getter() On the way .
Case a
scene : id by Long Type , The number is longer than 19 When the bit passes to the front end, it changes its value . Accuracy is lost .
terms of settlement : take Long Type conversion to String type , Solve the loss of accuracy .
Be careful : The field to be converted must be of wrapper type , Otherwise, the conversion will fail .
@JsonSerialize(using = ToStringSerializer.class)
private Long parentId; // Successful transformation
@JsonSerialize(using = ToStringSerializer.class)
private long parentId; // Conversion failed
Case 2
scene : Two decimal places of the amount shall be reserved , rounding
terms of settlement : Define methods
@JsonSerialize(using = CustomDecimalSerialize.class)
private BigDecimal totalCom;
CustomDecimalSerialize
public class CustomDecimalSerialize extends JsonSerializer<BigDecimal> {
private DecimalFormat df = new DecimalFormat("0.00");
@Override
public void serialize(BigDecimal value, JsonGenerator gen, SerializerProvider serializers)
throws IOException, JsonProcessingException {
if (value != null) {
df.setRoundingMode(RoundingMode.HALF_UP);
gen.writeString(df.format(value));
}
}
}
2、 @JsonProperty
@JsonProperty("xxx") Used on properties , This attribute is recognized as... When serializing and deserializing xxx
// Serialization will DATA_SOURCE mapping dataSource
@JsonProperty(value = "DATA_SOURCE")
private String dataSource;
3、@DateTimeFormat and @JsonFormat
@DateTimeFormat and @JsonFormat
Other links :
jackson Use @JsonSerialize format BigDecimal solve .00 Don't show problems
边栏推荐
- February 14, 2022, incluxdb survey - mind map
- 这本数学书AI圈都在转,资深ML研究员历时7年之作,免费电子版可看
- SVN添加文件时的错误处理:…\conf\svnserve.conf:12: Option expected
- php:&nbsp; The document cannot be displayed in Chinese
- Can newly graduated European college students get an offer from a major Internet company in the United States?
- 双链笔记 RemNote 综合评测:快速输入、PDF 阅读、间隔重复/记忆
- Anan's doubts
- 剑指 Offer 17. 打印从1到最大的n位数
- Logseq evaluation: advantages, disadvantages, evaluation, learning tutorial
- Some thoughts on business
猜你喜欢
![【R】 [density clustering, hierarchical clustering, expectation maximization clustering]](/img/a2/b287a5878761ee22bdbd535cae77eb.png)
【R】 [density clustering, hierarchical clustering, expectation maximization clustering]
![[Database Principle and Application Tutorial (4th Edition | wechat Edition) Chen Zhibo] [Chapter IV exercises]](/img/8b/bef94d11ac22e3762a570dab3a96fa.jpg)
[Database Principle and Application Tutorial (4th Edition | wechat Edition) Chen Zhibo] [Chapter IV exercises]

【电脑插入U盘或者内存卡显示无法格式化FAT32如何解决】

Detailed explanation of multithreading

Elk note 24 -- replace logstash consumption log with gohangout

Comprehensive evaluation of double chain notes remnote: fast input, PDF reading, interval repetition / memory

【历史上的今天】7 月 3 日:人体工程学标准法案;消费电子领域先驱诞生;育碧发布 Uplay

Flink SQL knows why (12): is it difficult to join streams? (top)

2022-02-11 heap sorting and recursion
![[Database Principle and Application Tutorial (4th Edition | wechat Edition) Chen Zhibo] [Chapter III exercises]](/img/b4/3442c62586306b4fceca992ce6294a.png)
[Database Principle and Application Tutorial (4th Edition | wechat Edition) Chen Zhibo] [Chapter III exercises]
随机推荐
The shortage of graphics cards finally came to an end: 3070ti for more than 4000 yuan, 2000 yuan cheaper than the original price, and 3090ti
The reasons why there are so many programming languages in programming internal skills
[Database Principle and Application Tutorial (4th Edition | wechat Edition) Chen Zhibo] [Chapter V exercises]
SSH login server sends a reminder
正则表达式
Introduction to the implementation principle of rxjs observable filter operator
mysqlbetween实现选取介于两个值之间的数据范围
PowerPoint 教程,如何在 PowerPoint 中将演示文稿另存为视频?
CVPR 2022 | 美团技术团队精选6篇优秀论文解读
Resolved (error in viewing data information in machine learning) attributeerror: target_ names
Server coding bug
JS 将伪数组转换成数组
Sword finger offer 11 Rotate the minimum number of the array
The difference between session and cookie
AI 考高数得分 81,网友:AI 模型也免不了“内卷”!
[Database Principle and Application Tutorial (4th Edition | wechat Edition) Chen Zhibo] [Chapter 6 exercises]
Kivy tutorial how to automatically load kV files
MyCms 自媒体商城 v3.4.1 发布,使用手册更新
Logseq 评测:优点、缺点、评价、学习教程
[Database Principle and Application Tutorial (4th Edition | wechat Edition) Chen Zhibo] [Chapter III exercises]