Java – Unable to deserialize instances of java.lang.String from START_ARRAY

Unable to deserialize instances of java.lang.String from START_ARRAY… here is a solution to the problem.

Unable to deserialize instances of java.lang.String from START_ARRAY

@JsonIgnoreProperties(ignoreUnknown = true)
public class TestResult {
private Map<String, String> datas;
>
......}

When I use RestTemplate as follows, I get an error message as the title

TestResult result= restTemplate.postForObject(AppConstants.URL +Secure/View/getTest",request, TestResult.class);

The data I tried to get when I use jmeter is correct, but I get an error on android (using RestTemplate)
Please help me solve it, thanks!

10-17 17:08:27.571: E//RequestProcessor.java:250(16865): 17:08:27.570 pool-12-thread-1 An exception occured during request network execution :Could not read JSON: Can not deserialize instance   of java.lang.String out of START_ARRAY token
10-17 17:08:27.571: E//RequestProcessor.java:250(16865):  at [Source: [email protected]; line: 1, column: 11] (through reference chain: model.vo.TestResult["datas"]); nested exception is org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.lang.String out of START_ARRAY token
10-17 17:08:27.571: E//RequestProcessor.java:250(16865):  at [Source: [email protected]; line: 1, column: 11] (through reference chain: model.vo.TestResult["datas"])
10-17 17:08:27.571: E//RequestProcessor.java:250(16865): org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Can not deserialize instance of java.lang.String out of START_ARRAY token
10-17 17:08:27.571: E//RequestProcessor.java:250(16865):  at [Source: [email protected]; line: 1, column: 11] (through reference chain: model.vo.TestResult["datas"]); nested exception is org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.lang.String out of START_ARRAY token
10-17 17:08:27.571: E//RequestProcessor.java:250(16865):  at [Source: [email protected]; line: 1, column: 11] (through reference chain: model.vo.TestResult["datas"])
10-17 17:08:27.571: E//RequestProcessor.java:250(16865):    at org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.readInternal( MappingJacksonHttpMessageConverter.java:125)
10-17 17:08:27.571: E//RequestProcessor.java:250(16865):    at org.springframework.http.converter.AbstractHttpMessageConverter.read(AbstractHttpMessageConverter.java:147)
10-17 17:08:27.571: E//RequestProcessor.java:250(16865):    at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:76 )
10-17 17:08:27.571: E//RequestProcessor.java:250(16865):    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:484)
10-17 17:08:27.571: E//RequestProcessor.java:250(16865):    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:439)
10-17 17:08:27.571: E//RequestProcessor.java:250(16865):    at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:317)
10-17 17:08:27.571: E//RequestProcessor.java:250(16865):    at service. TestRequest.loadDataFromNetwork(TestRequest.java:73)
10-17 17:08:27.571: E//RequestProcessor.java:250(16865):    at service. TestRequest.loadDataFromNetwork(TestRequest.java:1)
10-17 17:08:27.571: E//RequestProcessor.java:250(16865):    at com.octo.android.robospice.request.CachedSpiceRequest.loadDataFromNetwork(CachedSpiceRequest.java:27)

Solution

Examine the original response and try tapping the URL in a browser or REST client to see what is returned.

Could not read JSON: Can not deserialize instance of java.lang.String out of START_ARRAY token

Can not deserialize instance of java.lang.String out of START_ARRAY token
chain: model.vo.TestResult[“datas”])

It is difficult to determine based on this amount of information alone. It looks like the JSON response contains an array object, but the Java bean field is a string.

Related Problems and Solutions