当前位置:网站首页>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
边栏推荐
- Can newly graduated European college students get an offer from a major Internet company in the United States?
- php:&nbsp; The document cannot be displayed in Chinese
- 35道MySQL面试必问题图解,这样也太好理解了吧
- Today's sleep quality record 77 points
- 剑指 Offer 12. 矩阵中的路径
- 已解决(机器学习中查看数据信息报错)AttributeError: target_names
- Setting up Oracle datagurd environment
- The reasons why there are so many programming languages in programming internal skills
- R language uses the data function to obtain the sample datasets available in the current R environment: obtain all the sample datasets in the datasets package, obtain the datasets of all packages, and
- The principle of human voice transformer
猜你喜欢
[colab] [7 methods of using external data]
Sitescms v3.1.0 release, launch wechat applet
rxjs Observable filter Operator 的实现原理介绍
The 35 required questions in MySQL interview are illustrated, which is too easy to understand
Logseq 评测:优点、缺点、评价、学习教程
已解决(机器学习中查看数据信息报错)AttributeError: target_names
Seven habits of highly effective people
8皇后问题
【电脑插入U盘或者内存卡显示无法格式化FAT32如何解决】
【R】 [density clustering, hierarchical clustering, expectation maximization clustering]
随机推荐
AI 考高数得分 81,网友:AI 模型也免不了“内卷”!
Introduction to the implementation principle of rxjs observable filter operator
Road construction issues
常见的几种最优化方法Matlab原理和深度分析
Detailed explanation of multithreading
[sort] bucket sort
R语言gt包和gtExtras包优雅地、漂亮地显示表格数据:nflreadr包以及gtExtras包的gt_plt_winloss函数可视化多个分组的输赢值以及内联图(inline plot)
35道MySQL面试必问题图解,这样也太好理解了吧
Cadre de logback
Can newly graduated European college students get an offer from a major Internet company in the United States?
Flick SQL knows why (10): everyone uses accumulate window to calculate cumulative indicators
Logback 日志框架
Asp.Net Core1.1版本没了project.json,这样来生成跨平台包
[Database Principle and Application Tutorial (4th Edition | wechat Edition) Chen Zhibo] [Chapter V exercises]
[Database Principle and Application Tutorial (4th Edition | wechat Edition) Chen Zhibo] [Chapter IV exercises]
剑指 Offer 14- I. 剪绳子
Multi table query of MySQL - multi table relationship and related exercises
Tencent cloud tdsql database delivery and operation and maintenance Junior Engineer - some questions of Tencent cloud cloudlite certification (TCA) examination
【R】 [density clustering, hierarchical clustering, expectation maximization clustering]
Server coding bug