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