update字段变更SpringBoot @JsonProperty的使用属性的名称序列化为另外一个名称
?
?
https://blog.csdn.net/wtb617806038/article/details/86093301
?
Restful 接口調(diào)用Json接收相關(guān)問題
1、背景:
在項目上使用SpringBoot為框架,調(diào)用第三方接口時,返回的參數(shù)類型,不符合標準的命名規(guī)則,需要進行處理,接受數(shù)據(jù)
2、現(xiàn)象:
調(diào)用第三方接口返回數(shù)據(jù)格式為方式均為小寫,如下:
? ? ? ? ? {
????????????"rowid": "111111",
????????????"created": "2018-12-27 16:15:25",
????????????"createdby": "1111111",
????????????"lastupd": "2018-12-27 08:25:48",
????????????"lastupdby": "111111",
????????????"modificationnum": 1
????????? }
返回Json參數(shù)字段均為小寫,在接收時,需要按照標準的命名規(guī)則進行映射
3、解決辦法:
創(chuàng)建接收數(shù)據(jù)對象,生成Get\Set方法:,在Set方法上,加上@JsonProperty注解,
@JsonProperty 此注解用于屬性上,作用是把該屬性的名稱序列化為另外一個名稱,如把rowId屬性序列化為rowid,@JsonProperty("rowid")。
????private String rowId;
????private Date created;
????private String createdBy;
????private Date lastUpd;
? ? private String lastUpdBy;
?
? ? @JsonProperty("rowId")
????public String getRowId() {
????????return rowId;
??? }
?
????@JsonProperty("rowid")
????public void setRowId(String rowId) {
????????this.rowId = rowId;
??? }
?
????public Date getCreated() {
????????return created;
??? }
????@JsonDeserialize(using = CustomJsonDateDeserializer.class)
????public void setCreated(Date created) {
????????this.created = created;
??? }
?
????@JsonProperty("createdBy")
????public String getCreatedBy() {
????????return createdBy;
??? }
?
????@JsonProperty("createdby")
????public void setCreatedBy(String createdBy) {
????????this.createdBy = createdBy;
??? }
以上,就會將數(shù)據(jù)進行自動映射,獲取到數(shù)據(jù)
?
————————————————
版權(quán)聲明:本文為CSDN博主「小飛萌」的原創(chuàng)文章,遵循CC 4.0 BY-SA版權(quán)協(xié)議,轉(zhuǎn)載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/wtb617806038/article/details/86093301
總結(jié)
以上是生活随笔為你收集整理的update字段变更SpringBoot @JsonProperty的使用属性的名称序列化为另外一个名称的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 想自己组装个电脑,预算6000加水冷,求
- 下一篇: SpringMVC跨服务器上传文件中出现