我有傳入的 json 看起來像這樣:
{
"ref": {
"id": "1011"
},
"compset": [
{
"id": "23412"
},
{
"id": "27964"
},
{
"id": "51193"
},
{
"id": "74343"
},
{
"id": "537157"
},
{
"id": "542023"
},
{
"id": "601732"
},
{
"id": "793808"
},
{
"id": "891169"
},
{
"id": "1246443"
}
],
"isCompliant": false,
"updateTimestamp": null,
"remainingMilliseconds": 0,
"totalLockoutDays": 15
}
我有三個類來處理這個回應:
對于“id”欄位:
public class Competitor {
@JsonProperty("id")
@JsonFormat(shape = JsonFormat.Shape.NUMBER_INT)
private Integer id; // this should be integer, can't change the type
}
對于“compset”欄位:
public class PropertyCompetitorsModel {
private List<Competitor> competitors;
}
對于回應本身:
public class CompSetResponse {
@JsonProperty("compset")
private PropertyCompetitorsModel compset;
}
如您所見,我只需要 compset 欄位。
使用上面的代碼,我遇到了這個錯誤:
Cannot deserialize instance of PropertyCompetitorsModel out of START_ARRAY token
使用杰克遜庫
uj5u.com熱心網友回復:
請改用以下內容:
public class CompSetResponse {
@JsonProperty("compset")
private List<Competitor> compset;
}
您當前的代碼需要如下 JSON:
{
"ref": {
"id": "1011"
},
"compset": {
"competitors": [
{
"id": "23412"
},
{
"id": "27964"
},
{
"id": "51193"
},
{
"id": "74343"
},
{
"id": "537157"
},
{
"id": "542023"
},
{
"id": "601732"
},
{
"id": "793808"
},
{
"id": "891169"
},
{
"id": "1246443"
}
],
},
"isCompliant": false,
"updateTimestamp": null,
"remainingMilliseconds": 0,
"totalLockoutDays": 15
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/422248.html
標籤:
