当前位置:网站首页>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
边栏推荐
- Elk note 24 -- replace logstash consumption log with gohangout
- 2022-01-27 redis cluster technology research
- Road construction issues
- Asp.Net Core1.1版本没了project.json,这样来生成跨平台包
- Box layout of Kivy tutorial BoxLayout arranges sub items in vertical or horizontal boxes (tutorial includes source code)
- Annotation and reflection
- [Database Principle and Application Tutorial (4th Edition | wechat Edition) Chen Zhibo] [Chapter 7 exercises]
- MySQL installation, uninstallation, initial password setting and general commands of Linux
- STM32 and motor development (from MCU to architecture design)
- 2022-02-11 heap sorting and recursion
猜你喜欢

Solve system has not been booted with SYSTEMd as init system (PID 1) Can‘t operate.

My creation anniversary: the fifth anniversary

Road construction issues

Kivy教程之 盒子布局 BoxLayout将子项排列在垂直或水平框中(教程含源码)

Annotation and reflection
![[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]

双链笔记 RemNote 综合评测:快速输入、PDF 阅读、间隔重复/记忆

Kivy教程之 如何自动载入kv文件

已解决(机器学习中查看数据信息报错)AttributeError: target_names

elk笔记24--用gohangout替代logstash消费日志
随机推荐
STM32 and motor development (from MCU to architecture design)
35道MySQL面试必问题图解,这样也太好理解了吧
Sword finger offer 11 Rotate the minimum number of the array
OpenHarmony应用开发之ETS开发方式中的Image组件
[Database Principle and Application Tutorial (4th Edition | wechat Edition) Chen Zhibo] [Chapter 6 exercises]
Introduction to the implementation principle of rxjs observable filter operator
Logback 日志框架
双链笔记 RemNote 综合评测:快速输入、PDF 阅读、间隔重复/记忆
My creation anniversary: the fifth anniversary
物联网毕设 --(STM32f407连接云平台检测数据)
Logseq evaluation: advantages, disadvantages, evaluation, learning tutorial
解决 System has not been booted with systemd as init system (PID 1). Can‘t operate.
Useful blog links
File uploading and email sending
PowerPoint 教程,如何在 PowerPoint 中将演示文稿另存为视频?
Flink SQL knows why (12): is it difficult to join streams? (top)
PowerPoint tutorial, how to save a presentation as a video in PowerPoint?
The principle of human voice transformer
February 14, 2022, incluxdb survey - mind map
Task5: multi type emotion analysis