@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class MyRecord {
    private boolean succeed;
    private String  recordId;
    @JsonProperty("error_code")
    private int     errorCode;
    @JsonProperty("error_msg")
    private String  errorMsg;
}

一、Jackson转换属性

场景:json串传过来的属性名为error_code,但是我的模型User的属性为errorCode

    @JsonProperty("error_code")
    private int     errorCode;

二、Jackson忽略属性

场景:json串传来了20个属性,但是我只要其中的4个。

解决方案:在类上添加如下属性

@JsonIgnoreProperties(ignoreUnknown = true)

三、Jackson类型转换model需要空构造器

注意:注意这就说明,我们对于接收的model不要使用@Builder构造器模式(该注解是没有空构造器的)

相关文章:

  • 2022-12-23
  • 2021-04-20
  • 2021-08-01
  • 2021-06-26
  • 2021-08-19
  • 2021-06-10
猜你喜欢
  • 2022-12-23
  • 2021-06-08
  • 2022-12-23
  • 2022-12-23
  • 2022-01-30
  • 2022-12-23
  • 2021-07-10
相关资源
相似解决方案