0

我的请求对象是通过 openapi-generator-maven-plugin 基于 json 接口文件自动生成的。我想@JsonInclude(value = JsonInclude.Include.NON_NULL)在自动生成的类的一个属性(不是所有类或类的其他属性)之上有这个注释

以下是自动生成的:

@ApiModel(description = "blabla")
@JsonPropertyOrder({
  Request.JSON_PROPERTY_CONSENT_ID,
})
@JsonTypeName("Request")
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2022-02-17T13:14:32.020579400+01:00")
public class Request{
  public static final String JSON_PROPERTY_CONSENT_ID = "consentId";
  private Long consentId;

  @javax.annotation.Nullable
  @ApiModelProperty(value = "blabla")
  @JsonProperty(JSON_PROPERTY_CONSENT_ID)
  @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)

  public Long getConsentId() {
    return consentId;
  }

  @JsonProperty(JSON_PROPERTY_CONSENT_ID)
  @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS)
  public void setConsentId(Long consentId) {
    this.consentId = consentId;
  }

所以目前这段代码是用JsonInclude.Include.USE_DEFAULTS自动生成的,但我想要 JsonInclude.Include.NOT_NULL而不是。这可以实现吗?

我尝试使用

    spring:
  jackson:
    default-property-inclusion: NON_NULL

在 application.yml 文件中,但与 USE_DEFAULTS 的结果相同。我正在使用 Spring Boot 版本 2.1.4

4

0 回答 0