0

我的 POJO 是使用 json 文件从 swagger 2.0 自动生成的。我希望某些 POJO 具有注释 @JsonIgnoreProperties(ignoreUnknown = true) 作为类级别。注释来自 com.fasterxml.jackson.annotation.JsonIgnoreProperties。那么我怎样才能为特定的 POJO 自动生成这个注释呢?

例如这是我的 POJO

    "MappingPJO": {
          "type": "object",
          "required": [
            "X-ID",
            "data",
            "datacontenttype",
            "specversion",
            "type"
          ],
          "properties": {
            "X-ID": {
              "type": "string",
              "example": "3cf50cc1-04df-492e-8868-9f135e6c0e05"
            },
            "data": {
              "description": "the data of the mapping event",
              "$ref": "#/definitions/MappingEventData"
            },
            "datacontenttype": {
              "type": "string",
              "example": "application/json",
              "description": "the content type of the mapping event"
            },
            "specversion": {
              "type": "string",
              "example": "1",
              "description": "the specification version of the mapping event"
            },
            "type": {
              "type": "string",
              "example": "MAPPING_CREATED",
              "description": "defines the type of the mapping event"
            }
          },
          "title": "MappingCreatedPOJO",
          
"description": "Data of a successful primary info creation event"
    }

我想将自动生成的 pojo 设为:

@ApiModel(description = "Data of a successful primary info creation event")
@JsonPropertyOrder({
  MappingCreatedPOJO.JSON_PROPERTY_X_I_D,
  MappingCreatedPOJO.JSON_PROPERTY_DATA,
  MappingCreatedPOJO.JSON_PROPERTY_DATACONTENTTYPE,
  MappingCreatedPOJO.JSON_PROPERTY_SPECVERSION,
  MappingCreatedPOJO.JSON_PROPERTY_TYPE
})
@JsonTypeName("MappingCreatedPOJO")
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2021-12-14T09:01:24.289539")
@JsonIgnoreProperties(ignoreUnknown = true) //// WANT THIS ANNOTATION
public class MappingCreatedPOJO{
  public static final String JSON_PROPERTY_X_I_D = "X-ID";
  private String xID;

.....
4

0 回答 0