如何从此示例JSON创建POJO?

时间:2017-06-24 14:12:29

标签: java json pojo jsonschema2pojo

我正在尝试从https://developers.google.com/qpx-express/v1/trips/search

的API为以下JSON创建POJO

当我复制&将其粘贴到http://www.jsonschema2pojo.org/我在第5行"requestId": string,收到错误,说“有问题:无法识别的令牌'字符串':期待('true','false'或'null')(第5行) ,第24栏“”

如果我将string更改为实际的示例字符串,则可以正常工作。这个json to pojo转换器能否以这种格式处理JSON?将所有数据类型更改为样本似乎有点乏味。

{
  "kind": "qpxExpress#tripsSearch",
  "trips": {
    "kind": "qpxexpress#tripOptions",
    "requestId": string,
    "data": {
      "kind": "qpxexpress#data",
      "airport": [
        {
          "kind": "qpxexpress#airportData",
          "code": string,
          "city": string,
          "name": string
        }
      ],
      "city": [
        {
          "kind": "qpxexpress#cityData",
          "code": string,
          "country": string,
          "name": string
        }
      ],
      "aircraft": [
        {
          "kind": "qpxexpress#aircraftData",
          "code": string,
          "name": string
        }
      ],
      "tax": [
        {
          "kind": "qpxexpress#taxData",
          "id": string,
          "name": string
        }
      ],
      "carrier": [
        {
          "kind": "qpxexpress#carrierData",
          "code": string,
          "name": string
        }
      ]
    },
    "tripOption": [
      {
        "kind": "qpxexpress#tripOption",
        "saleTotal": string,
        "id": string,
        "slice": [
          {
            "kind": "qpxexpress#sliceInfo",
            "duration": integer,
            "segment": [
              {
                "kind": "qpxexpress#segmentInfo",
                "duration": integer,
                "flight": {
                  "carrier": string,
                  "number": string
                },
                "id": string,
                "cabin": string,
                "bookingCode": string,
                "bookingCodeCount": integer,
                "marriedSegmentGroup": string,
                "subjectToGovernmentApproval": boolean,
                "leg": [
                  {
                    "kind": "qpxexpress#legInfo",
                    "id": string,
                    "aircraft": string,
                    "arrivalTime": string,
                    "departureTime": string,
                    "origin": string,
                    "destination": string,
                    "originTerminal": string,
                    "destinationTerminal": string,
                    "duration": integer,
                    "operatingDisclosure": string,
                    "onTimePerformance": integer,
                    "mileage": integer,
                    "meal": string,
                    "secure": boolean,
                    "connectionDuration": integer,
                    "changePlane": boolean
                  }
                ],
                "connectionDuration": integer
              }
            ]
          }
        ],
        "pricing": [
          {
            "kind": "qpxexpress#pricingInfo",
            "fare": [
              {
                "kind": "qpxexpress#fareInfo",
                "id": string,
                "carrier": string,
                "origin": string,
                "destination": string,
                "basisCode": string,
                "private": boolean
              }
            ],
            "segmentPricing": [
              {
                "kind": "qpxexpress#segmentPricing",
                "fareId": string,
                "segmentId": string,
                "freeBaggageOption": [
                  {
                    "kind": "qpxexpress#freeBaggageAllowance",
                    "bagDescriptor": [
                      {
                        "kind": "qpxexpress#bagDescriptor",
                        "commercialName": string,
                        "count": integer,
                        "description": [
                          string
                        ],
                        "subcode": string
                      }
                    ],
                    "kilos": integer,
                    "kilosPerPiece": integer,
                    "pieces": integer,
                    "pounds": integer
                  }
                ]
              }
            ],
            "baseFareTotal": string,
            "saleFareTotal": string,
            "saleTaxTotal": string,
            "saleTotal": string,
            "passengers": {
              "kind": "qpxexpress#passengerCounts",
              "adultCount": integer,
              "childCount": integer,
              "infantInLapCount": integer,
              "infantInSeatCount": integer,
              "seniorCount": integer
            },
            "tax": [
              {
                "kind": "qpxexpress#taxInfo",
                "id": string,
                "chargeType": string,
                "code": string,
                "country": string,
                "salePrice": string
              }
            ],
            "fareCalculation": string,
            "latestTicketingTime": string,
            "ptc": string,
            "refundable": boolean
          }
        ]
      }
    ]
  }
}

2 个答案:

答案 0 :(得分:0)

嗯,页面上的示例JSON代码使用引号中的数据类型,因此"string"代替string。你可以做到这一点: (警告!如果你想要其他类型而不是字符串,下面的例子是无稽之谈!)

{
  "kind": "qpxExpress#tripsSearch",
  "trips": {
    "kind": "qpxexpress#tripOptions",
    "requestId": "string",
    "data": {
      "kind": "qpxexpress#data",
      "airport": [
        {
          "kind": "qpxexpress#airportData",
          "code": "string",
          "city": "string",
          "name": "string"
        }
      ],
      "city": [
        {
          "kind": "qpxexpress#cityData",
          "code": "string",
          "country": "string",
          "name": "string"
        }
      ],
      "aircraft": [
        {
          "kind": "qpxexpress#aircraftData",
          "code": "string",
          "name": "string"
        }
      ],
      "tax": [
        {
          "kind": "qpxexpress#taxData",
          "id": "string",
          "name": "string"
        }
      ],
      "carrier": [
        {
          "kind": "qpxexpress#carrierData",
          "code": "string",
          "name": "string"
        }
      ]
    },
    "tripOption": [
      {
        "kind": "qpxexpress#tripOption",
        "saleTotal": "string",
        "id": "string",
        "slice": [
          {
            "kind": "qpxexpress#sliceInfo",
            "duration": "integer",
            "segment": [
              {
                "kind": "qpxexpress#segmentInfo",
                "duration": "integer",
                "flight": {
                  "carrier": "string",
                  "number": "string"
                },
                "id": "string",
                "cabin": "string",
                "bookingCode": "string",
                "bookingCodeCount": "integer",
                "marriedSegmentGroup": "string",
                "subjectToGovernmentApproval": "boolean",
                "leg": [
                  {
                    "kind": "qpxexpress#legInfo",
                    "id": "string",
                    "aircraft": "string",
                    "arrivalTime": "string",
                    "departureTime": "string",
                    "origin": "string",
                    "destination": "string",
                    "originTerminal": "string",
                    "destinationTerminal": "string",
                    "duration": "integer",
                    "operatingDisclosure": "string",
                    "onTimePerformance": "integer",
                    "mileage": "integer",
                    "meal": "string",
                    "secure": "boolean",
                    "connectionDuration": "integer",
                    "changePlane": "boolean"
                  }
                ],
                "connectionDuration": "integer"
              }
            ]
          }
        ],
        "pricing": [
          {
            "kind": "qpxexpress#pricingInfo",
            "fare": [
              {
                "kind": "qpxexpress#fareInfo",
                "id": "string",
                "carrier": "string",
                "origin": "string",
                "destination": "string",
                "basisCode": "string",
                "private": "boolean"
              }
            ],
            "segmentPricing": [
              {
                "kind": "qpxexpress#segmentPricing",
                "fareId": "string",
                "segmentId": "string",
                "freeBaggageOption": [
                  {
                    "kind": "qpxexpress#freeBaggageAllowance",
                    "bagDescriptor": [
                      {
                        "kind": "qpxexpress#bagDescriptor",
                        "commercialName": "string",
                        "count": "integer",
                        "description": [
                          "string"
                        ],
                        "subcode": "string"
                      }
                    ],
                    "kilos": "integer",
                    "kilosPerPiece": "integer",
                    "pieces": "integer",
                    "pounds": "integer"
                  }
                ]
              }
            ],
            "baseFareTotal": "string",
            "saleFareTotal": "string",
            "saleTaxTotal": "string",
            "saleTotal": "string",
            "passengers": {
              "kind": "qpxexpress#passengerCounts",
              "adultCount": "integer",
              "childCount": "integer",
              "infantInLapCount": "integer",
              "infantInSeatCount": "integer",
              "seniorCount": "integer"
            },
            "tax": [
              {
                "kind": "qpxexpress#taxInfo",
                "id": "string",
                "chargeType": "string",
                "code": "string",
                "country": "string",
                "salePrice": "string"
              }
            ],
            "fareCalculation": "string",
            "latestTicketingTime": "string",
            "ptc": "string",
            "refundable": "boolean"
          }
        ]
      }
    ]
  }
}

答案 1 :(得分:0)

有效的json要求字符串值在引号中。所以引用密钥而不是像 - >这样的值。 “id”:字符串,没有多大意义。请仔细阅读“在请求正文中,使用以下结构提供数据”您没有提供任何数据