我想解析 json 值,但有些值沒有鍵。像這樣"geometry": { "type": "LineString", "coordinates": [ [ 127.08373748622218, 37.529508099979225 ], [ 127.08355138558433, 37.529735847943925 ] ] }幾何類@Getter@NoArgsConstructor(access = AccessLevel.PROTECTED)@ToStringpublic class Geometry { private String type; private Coordinate coordinates;}坐標類@Getter@NoArgsConstructor(access = AccessLevel.PROTECTED)@ToStringpublic class Coordinate { private List<Double[]> xy;}然后我看到了這個錯誤Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `kr.seoulmaas.ieye.service.dto.path.walk.Coordinate` out of START_ARRAY token at [Source: (PushbackInputStream); line: 1, column: 133] (through reference chain: kr.seoulmaas.ieye.service.dto.path.WalkPathResDto["features"]->java.util.ArrayList[0]->kr.seoulmaas.ieye.service.dto.path.walk.Feature["geometry"]->kr.seoulmaas.ieye.service.dto.path.walk.Geometry["coordinates"])
3 回答

MMTTMM
TA貢獻1869條經驗 獲得超4個贊
private Coordinate coordinates;
應該是private List<Coordinate> coordinates;
因為它是 JSON 中的一個數組,但由于該數組僅包含數組,因此您需要有一個列表列表:List<List<Double>> coordinates
(@JBNizet 建議)。

千巷貓影
TA貢獻1829條經驗 獲得超7個贊
對不起,我來晚了。
我使用 JsonNode 解決了這個問題。
這是我的代碼。
public class Geometry {
private String type;
private JsonNode coordinates;
}

桃花長相依
TA貢獻1860條經驗 獲得超8個贊
在您的數據中,coordinates是list. list因此,以這種方式定義您的 Geometry 類:
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@ToString
public class Geometry {
private String type;
private List<Coordinate> coordinates;
}
希望這可以幫助。
添加回答
舉報
0/150
提交
取消