javascript
update字段变更SpringBoot @JsonProperty的使用属性的名称序列化为另外一个名称
?
?
https://blog.csdn.net/wtb617806038/article/details/86093301
?
Restful 接口調用Json接收相關問題
1、背景:
在項目上使用SpringBoot為框架,調用第三方接口時,返回的參數類型,不符合標準的命名規則,需要進行處理,接受數據
2、現象:
調用第三方接口返回數據格式為方式均為小寫,如下:
? ? ? ? ? {
????????????"rowid": "111111",
????????????"created": "2018-12-27 16:15:25",
????????????"createdby": "1111111",
????????????"lastupd": "2018-12-27 08:25:48",
????????????"lastupdby": "111111",
????????????"modificationnum": 1
????????? }
返回Json參數字段均為小寫,在接收時,需要按照標準的命名規則進行映射
3、解決辦法:
創建接收數據對象,生成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;
??? }
以上,就會將數據進行自動映射,獲取到數據
?
————————————————
版權聲明:本文為CSDN博主「小飛萌」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/wtb617806038/article/details/86093301
總結
以上是生活随笔為你收集整理的update字段变更SpringBoot @JsonProperty的使用属性的名称序列化为另外一个名称的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 想自己组装个电脑,预算6000加水冷,求
- 下一篇: SpringMVC跨服务器上传文件中出现