当前位置:网站首页>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
边栏推荐
- 正则表达式
- 2022-01-27 use liquibase to manage MySQL execution version
- 2022-02-11 heap sorting and recursion
- 已解决(机器学习中查看数据信息报错)AttributeError: target_names
- 2022-01-27 research on the minimum number of redis partitions
- regular expression
- mysqlbetween实现选取介于两个值之间的数据范围
- 阿南的疑惑
- OpenHarmony应用开发之ETS开发方式中的Image组件
- Multi table query of MySQL - multi table relationship and related exercises
猜你喜欢
[Database Principle and Application Tutorial (4th Edition | wechat Edition) Chen Zhibo] [sqlserver2012 comprehensive exercise]
人身变声器的原理
[Database Principle and Application Tutorial (4th Edition | wechat Edition) Chen Zhibo] [Chapter IV exercises]
Kivy教程之 如何自动载入kv文件
[email protected] chianxin: Perspective of Russian Ukrainian cyber war - Security confrontation and sanctions g"/>
Start signing up CCF C ³- [email protected] chianxin: Perspective of Russian Ukrainian cyber war - Security confrontation and sanctions g
File uploading and email sending
Flink code is written like this. It's strange that the window can be triggered (bad programming habits)
My creation anniversary: the fifth anniversary
DQL basic query
When we are doing flow batch integration, what are we doing?
随机推荐
2022-02-14 analysis of the startup and request processing process of the incluxdb cluster Coordinator
stm32和电机开发(从mcu到架构设计)
Comprehensive evaluation of double chain notes remnote: fast input, PDF reading, interval repetition / memory
MapReduce实现矩阵乘法–实现代码
用户和组命令练习
Annotation and reflection
Kivy教程之 盒子布局 BoxLayout将子项排列在垂直或水平框中(教程含源码)
IDEA 全文搜索快捷键Ctr+Shift+F失效问题
今日睡眠质量记录77分
SVN添加文件时的错误处理:…\conf\svnserve.conf:12: Option expected
Anan's doubts
AI scores 81 in high scores. Netizens: AI model can't avoid "internal examination"!
Smbms project
Flink SQL knows why (VIII): the wonderful way to parse Flink SQL tumble window
Server coding bug
Tencent cloud tdsql database delivery and operation and maintenance Junior Engineer - some questions of Tencent cloud cloudlite certification (TCA) examination
Flink SQL knows why (7): haven't you even seen the ETL and group AGG scenarios that are most suitable for Flink SQL?
When we are doing flow batch integration, what are we doing?
Image component in ETS development mode of openharmony application development
【电脑插入U盘或者内存卡显示无法格式化FAT32如何解决】