Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

json reading error in robospice

Logcat error

07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): 06:43:48.147 Thread-9164 An exception occurred during request network execution :Could not read JSON: Can not deserialize instance of java.lang.String out of START_OBJECT token
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678):  at [Source: java.util.zip.GZIPInputStream@420e4cc8; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678):  at [Source: java.util.zip.GZIPInputStream@420e4cc8; line: 1, column: 1]
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Can not deserialize instance of java.lang.String out of START_OBJECT token
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678):  at [Source: java.util.zip.GZIPInputStream@420e4cc8; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678):  at [Source: java.util.zip.GZIPInputStream@420e4cc8; line: 1, column: 1]
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678):    at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.readInternal(MappingJackson2HttpMessageConverter.java:126)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678):    at org.springframework.http.converter.AbstractHttpMessageConverter.read(AbstractHttpMessageConverter.java:147)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678):    at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:76)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678):    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:484)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678):    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:439)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678):    at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:317)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678):    at com..rb.PostRequest.loadDataFromNetwork(PostRequest.java:90)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678):    at com..rb.PostRequest.loadDataFromNetwork(PostRequest.java:1)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678):    at com.octo.android.robospice.request.CachedSpiceRequest.loadDataFromNetwork(CachedSpiceRequest.java:45)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678):    at com.octo.android.robospice.request.DefaultRequestRunner.processRequest(DefaultRequestRunner.java:149)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678):    at com.octo.android.robospice.request.DefaultRequestRunner$1.run(DefaultRequestRunner.java:216)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678):    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678):    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678):    at java.lang.Thread.run(Thread.java:841)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678):  at [Source: java.util.zip.GZIPInputStream@420e4cc8; line: 1, column: 1]
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678):    at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:575)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678):    at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:46)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678):    at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:11)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678):    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2888)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678):    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2094)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678):    at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.readInternal(MappingJackson2HttpMessageConverter.java:123)

and this is my code in using robospice

RestTemplate restTemplate = new RestTemplate();

 // Add the Jackson and String message converters
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
restTemplate.getMessageConverters().add(new StringHttpMessageConverter());

// Make the HTTP POST request, marshaling the request to JSON, and the response to a 
String response = restTemplate.postForObject(url, message, String.class);
return response;

Note: this same code is working fine some of the json output, some different kind of json, I'm getting this error, I tried to find out the json structure where exactly but what I feel both are same, so I get confused, at the same time I shout the reason of this error

like image 962
Issac Balaji Avatar asked Dec 20 '22 12:12

Issac Balaji


2 Answers

List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
messageConverters.add(new FormHttpMessageConverter());
messageConverters.add(new StringHttpMessageConverter());
messageConverters.add(new MappingJacksonHttpMessageConverter());
restTemplate.setMessageConverters(messageConverters);

now i got solution but don't how and all but i could understand that the problem for reading json ,as per my understanding the conversion of the jackson from json to string just i changed and added these converted, then is working fine

like image 149
Issac Balaji Avatar answered Dec 22 '22 01:12

Issac Balaji


It looks like the json you receive contains an object, not a string as you would expect. This is RS usage and Jackson, not RS itself.

like image 20
Snicolas Avatar answered Dec 22 '22 02:12

Snicolas