0

我有这样的 openAPI 定义:

  JobWithAnyType:
    properties:
      jobProperty:
       type: object
  BasicJobProperty:
    discriminator:
      propertyName: anyType

BasicJobProperty 使用以下注释生成:
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "anyType", visible = true)
@JsonTypeName("BasicJobProperty")

我像这样使用杰克逊序列化程序:

    JobWithAnyType job = new JobWithAnyType();
    Object jobProperty = new BasicJobProperty();
    job.setJobProperty(jobProperty);

    ObjectMapper objectMapper = new ObjectMapper();
    String json = objectMapper.writeValueAsString(job);

    Expected :{"jobProperty":{"anyType":"BasicJobProperty"}}<br/>
    Actual   :{"jobProperty":{}}

是否可以修复 Jackson 序列化(通过不同的 Jackson 注释或其他方式),以便将 jobProperty 识别为 BasicJobProperty?

4

0 回答 0