Swagger生成的Java对象将无法正确映射JSON请求

时间:2019-10-09 12:05:07

标签: java rest yaml swagger openapi

这是我的JSON POST请求示例:

{
    "batch": {
        "header": {
            "id": 123,
            "id2": 234,
            "msg": 4,
            "time": "01",
            "id3": "str1234"
        },
        "dataStuff": {
            "prod": {
                "bi": "true",
                "pd": "true"
            },
            "nmb": "str1234",
            "date": "2012-12-13",
            "sett": {
                "type": "str1234",
                "net": "str1234",
                "general": "str1234",
                "date": "str1234",
                "low": 12,
                "high": 12
            }
        }
    }
}

我的Swagger openapi 3.0.0 .yaml模式:

schemas:
    batch:
      type: object
      properties:
        header:
          type: object
          properties:
            id:
              type: string
            id2:
              type: string
            msg:
              type: string
            time:
              type: string
            id3:
              type: string
        dataStuff:
          type: object
          properties:
            prod:
              type: object
              properties:
                bi:
                  type: string
                pd:
                  type: string
            nmb:
              type: string
            date:
              type: string
              format: date
            sett:
              type: object
              properties:
                type:
                  type: string
                net:
                  type: string
                general:
                  type: string
                date:
                  type: string
                low:
                  type: string
                high:
                  type: string

使用上述yaml生成Java模型后,我发送了POST请求。我打印出该请求的正文并得到:

class batch{
    header: null
    dataStuff: null
}

@JsonProperty无法映射所有嵌套对象中的所有值。我究竟做错了什么?我不知道有什么其他写.yaml来支持嵌套对象的方式。

0 个答案:

没有答案