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.cl ient.RestC lientExcep tion: Error while extracting response for type [java.util.List<?>] and content type [application/json;charset= UTF-8]; nested exception is org.springframework.http.c onverter.H ttpMessage NotReadabl eException : JSON parse error: Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token; nested exception is com.fasterxml.jackson.data bind.exc.M ismatchedI nputExcept ion: Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token at [Source: (PushbackInputStream); line: 1, column: 1] at org.springframework.web.cl ient.HttpM essageConv erterExtra ctor.extra ctData(Htt pMessageCo nverterExt ractor.jav a:115) at org.springframework.web.cl ient.RestT emplate$Re sponseEnti tyResponse Extractor. extractDat a(RestTemp late.java: 991) at org.springframework.web.cl ient.RestT emplate$Re sponseEnti tyResponse Extractor. extractDat a(RestTemp late.java: 974) at org.springframework.web.cl ient.RestT emplate.do Execute(Re stTemplate .java:725) at org.springframework.web.cl ient.RestT emplate.ex ecute(Rest Template.j ava:698) at org.springframework.web.cl ient.RestT emplate.ex change(Res tTemplate. java:649) at com.finger.services.AppRes tTemplateS ervice.doH andleListR equest(App RestTempla teService. java:140) at
Please, assist
Please help, how can I avoid this exception. It happens when my http response includes an empty List in the body.
org.springframework.web.cl
Please, assist
Make sure you're not treating what is really a single object as a List
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(...
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 TRIALMembers 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.