Link to home
Start Free TrialLog in
Avatar of Omer-Pitou
Omer-Pitou

asked on

SPRING : Can't deserialize an empty List object

Dear sirs,
Please help, how can I avoid this exception. It happens when my http response includes an empty List in the body.

org.springframework.web.client.RestClientException: Error while extracting response for type [java.util.List<?>] and content type [application/json;charset=UTF-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token at [Source: (PushbackInputStream); line: 1, column: 1] at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:115) at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:991) at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:974) at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:725) at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:698) at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:649) at com.finger.services.AppRestTemplateService.doHandleListRequest(AppRestTemplateService.java:140) at

Please, assist
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Make sure you're not treating what is really a single object as a List
Avatar of Omer-Pitou
Omer-Pitou

ASKER

Hi CEHJ, it is a list. The fact is that when it is empty it gives that exception. With sample data it works.
It is included in a web service, and I have a custom RestTemplateService to handle all my request and specify List<?> in my restTemplate.exchange(...
I wouldn't have thought that a List being empty should be any kind of a problem (if it really IS a list) but I'll let someone else take over now as i don't have direct experience with the software you're using.
Can you provide an example of the JSON that you are receiving that causes the Exception?
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.