无法反序列化对象的实例出来START_ARRAY令牌春季3 REST web服务 [英] Cannot deserialize instance of object out of START_ARRAY token in Spring 3 REST Webservice

查看:11136
本文介绍了无法反序列化对象的实例出来START_ARRAY令牌春季3 REST web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我利用这个很酷的事情Spring提供:春天RESTWebService(春天的版本是3)。如果我从浏览器访问URL,我可以看到JSON响应,但是从客户终端(Android应用程序)iIreceive此错误消息:

I am making use of this cool thing Spring offers: Spring RESTWebService (Version of spring is 3). If I access the URL from browser I can see the JSON response, but from a Client endpoint (Android application) iIreceive this error message:

Caused by: org.springframework.web.client.ResourceAccessException: 
    I/O error: Can not deserialize instance of MyObject out of START_ARRAY token
  at [Source: org.apache.http.conn.EofSensorInputStream@4076e940; line: 1, 
    column: 1]; nested exception is org.codehaus.jackson.map.JsonMappingException: 
    Can not deserialize instance of MyObject  out of START_ARRAY token
  at [Source: org.apache.http.conn.EofSensorInputStream@4076e940; line: 1, column: 1]
   at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:466)
   at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:414)
   at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:234)
   at com.be.android.locateconsultants.resources.AsyncTaskRESTServiceCaller.doInBackground(AsyncTaskRESTServiceCaller.java:43)
   at com.be.android.locateconsultants.resources.AsyncTaskRESTServiceCaller.doInBackground(AsyncTaskRESTServiceCaller.java:1)
   at android.os.AsyncTask$2.call(AsyncTask.java:252)
   at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
   ... 4 more

 Caused by: org.codehaus.jackson.map.JsonMappingException: Can not deserialize 
    instance of MyObject  out of START_ARRAY token
  at [Source: org.apache.http.conn.EofSensorInputStream@4076e940; line: 1, column: 1]
   at org.codehaus.jackson.map.deser.StdDeserializationContext.mappingException(StdDeserializationContext.java:198)
   at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeUsingCreator(BeanDeserializer.java:565)
   at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:365)
   at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2395)
   at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1655)
   at org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.readInternal(MappingJacksonHttpMessageConverter.java:135)
   at org.springframework.http.converter.AbstractHttpMessageConverter.read(AbstractHttpMessageConverter.java:154)
   at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:74)
   at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:632)
   at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:618)
   at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:459)
   ... 10 more

为MyObject结构是相同的,从服务器侧的应用程序之一。

MyObject structure is the same as the one from the server side application.

我试图向服务器请求是这样的:

I have tried to request the server like this:

final String url = ".....";
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<Consultant> responseEntity = restTemplate.getForEntity(
            url, Consultant.class);

或者是这样的:

Or like this:

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> entity = new HttpEntity<String>(headers);
ResponseEntity<MyObject> response = restTemplate
            .exchange("....",HttpMethod.GET, entity, MyObject.class);
System.out.println("RESPONSE: " + response.getBody());

不过还是同样的错误如上。 想不通,我此时缺少的东西,任何想法或提示将是巨大的。 谢谢你。

But still the same error as above. Can't figure out what I am missing at this point, any idea or hints would be great. Thank you.

推荐答案

在类似情况下的解决方案是映射到顾问[]。类 这适用于当您尝试反序列化映射对象的JSON数组。

Solution in a similar situation was to map to Consultant[].class This applies if you try to deserialize a JSON array of your mapped objects.

这篇关于无法反序列化对象的实例出来START_ARRAY令牌春季3 REST web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆