当前位置:网站首页>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
边栏推荐
- STM32 and motor development (from MCU to architecture design)
- regular expression
- File uploading and email sending
- Annotation and reflection
- Red Hat Satellite 6:更好地管理服务器和云
- php:&nbsp; The document cannot be displayed in Chinese
- Kotlin - improved decorator mode
- DQL basic query
- 剑指 Offer 15. 二进制中1的个数
- February 14, 2022, incluxdb survey - mind map
猜你喜欢

The difference between stratifiedkfold (classification) and kfold (regression)

stm32和电机开发(从mcu到架构设计)

解决 System has not been booted with systemd as init system (PID 1). Can‘t operate.

regular expression

DQL basic query

MyCms 自媒体商城 v3.4.1 发布,使用手册更新

MySQL functions and related cases and exercises

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

2022-02-11 heap sorting and recursion

Flick SQL knows why (10): everyone uses accumulate window to calculate cumulative indicators
随机推荐
开始报名丨CCF C³[email protected]奇安信:透视俄乌网络战 —— 网络空间基础设施面临的安全对抗与制裁博弈...
[sort] bucket sort
Luogup3694 Bangbang chorus standing in line
The difference between session and cookie
解决 System has not been booted with systemd as init system (PID 1). Can‘t operate.
2022-01-27 use liquibase to manage MySQL execution version
MyCms 自媒体商城 v3.4.1 发布,使用手册更新
json序列化时案例总结
Image component in ETS development mode of openharmony application development
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]
剑指 Offer 14- I. 剪绳子
71 articles on Flink practice and principle analysis (necessary for interview)
Reptile
Start signing up CCF C ³- [email protected] chianxin: Perspective of Russian Ukrainian cyber war - Security confrontation and sanctions g
[Database Principle and Application Tutorial (4th Edition | wechat Edition) Chen Zhibo] [Chapter III exercises]
Comprehensive evaluation of double chain notes remnote: fast input, PDF reading, interval repetition / memory
JS 将伪数组转换成数组
OpenHarmony应用开发之ETS开发方式中的Image组件
STM32 and motor development (from MCU to architecture design)