Satoshi
Satoshi

Reputation: 41

[Spring-boot, restTemplate]JSON parse error: Cannot deserialize value of type XXXX from Object value (token `JsonToken.START_OBJECT`)

I use Spring-boot and RestTemplate. I'm having trouble translating from json to Dto.

Client

Items items = restTemplate.getForObject("https://xxxxx/xxxxx, Items.class);

Items

@Getter
@Setter
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = false)
public class Items {

    private List<Item> Items;

    public Items() {
        Items = new ArrayList<>();
    }

    @Override
    public String toString() {
        return String.valueOf(Items.size());
    }
}

Item

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
public class Item {

    private String title;

    @Override
    public String toString() {
        return "Item{" + "title=" + title + '}';
    }

}

Json is here(formatted).

{
  "Items": [
    {
      "Item": {
        "limitedFlag": 0,
        "authorKana": "XXX",
        "author": "XXX",
        "subTitle": "XXX",
        "seriesNameKana": "XXXX",
        "title": "XXXX",
        "subTitleKana": "XXXX"
      }
    },
    {
      "Item": {
        "limitedFlag": 0,
        "authorKana": "XXX",
        "author": "XXX",
        "subTitle": "XXX",
        "seriesNameKana": "XXXX",
        "title": "XXXX",
        "subTitleKana": "XXXX"
      }
    }
  ],
  "last": 30
}

I receive this error message:

Caused by: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `[Ldev.itboot.mb.rest.Item;` from Object value (token `JsonToken.START_OBJECT`); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `[Ldev.itboot.mb.rest.Item;` from Object value (token `JsonToken.START_OBJECT`)

I looked here and on google but still cannot figure out.

Any response would be helpful.

Regards.

Upvotes: 4

Views: 15762

Answers (1)

Roger Lindsj&#246;
Roger Lindsj&#246;

Reputation: 11553

The end of your JSON seem incorrect, there should be a comma after the array, before "last".

  ]
  "last": 30
}

Upvotes: 1

Related Questions