首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >org.codehaus.jackson.map.JsonMappingException:不能将java.util.ArrayList的实例反序列化出START_OBJECT令牌

org.codehaus.jackson.map.JsonMappingException:不能将java.util.ArrayList的实例反序列化出START_OBJECT令牌
EN

Stack Overflow用户
提问于 2016-12-24 05:45:40
回答 1查看 874关注 0票数 1

我开发了一个Spring MVC+ RestEasy+Hibernate示例,并希望使用Junit对其进行测试,但请参阅下面的错误:我还可以通过jsp或rest客户端调用这些web服务。

代码语言:javascript
复制
org.jboss.resteasy.spi.ReaderException: org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
 at [Source: org.jboss.resteasy.client.core.SelfExpandingBufferredInputStream@23c30a20; line: 1, column: 1]
    at org.jboss.resteasy.client.core.BaseClientResponse.readFrom(BaseClientResponse.java:470)
    at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:385)
    at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:346)
    at test.resteasy.series.spring.mvc.hibernate.service.CustomerTest.testGetallcustomer(CustomerTest.java:19)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
 at [Source: org.jboss.resteasy.client.core.SelfExpandingBufferredInputStream@23c30a20; line: 1, column: 1]
    at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)
    at org.codehaus.jackson.map.deser.StdDeserializationContext.mappingException(StdDeserializationContext.java:219)
    at org.codehaus.jackson.map.deser.StdDeserializationContext.mappingException(StdDeserializationContext.java:212)
    at org.codehaus.jackson.map.deser.std.CollectionDeserializer.handleNonArray(CollectionDeserializer.java:246)
    at org.codehaus.jackson.map.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:204)
    at org.codehaus.jackson.map.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:194)
    at org.codehaus.jackson.map.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:30)
    at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2704)
    at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1315)
    at org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:419)
    at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.readFrom(AbstractReaderInterceptorContext.java:59)
    at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:51)
    at org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.aroundReadFrom(GZIPDecodingInterceptor.java:59)
    at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:53)
    at org.jboss.resteasy.client.core.BaseClientResponse.readFrom(BaseClientResponse.java:434)
    ... 26 more

下面是我开发的Junit测试:

代码语言:javascript
复制
public class CustomerTest {
    static final String ROOT_URL = "http://localhost:8080/RestEasy-Spring-MVC-Hibernate/resteasy/";

    @Test
    public void testGetallcustomer() throws Exception {
        ClientRequest request = new ClientRequest(ROOT_URL+"customerservice/getallcustomer");
        ClientResponse<List<Customer>> response = request.get(new GenericType<List<Customer>>(){});
        List<Customer> customers = response.getEntity();
        System.out.println("SIZE : "+customers.size());

    }
}

另外,API看起来也被废弃了:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-12-24 13:31:34

我并不是说这是解决问题的方法。这是另一种解决问题的办法。

代码语言:javascript
复制
public class CustomerTest {
    final String path = "http://localhost:8080/RestEasy-Spring-MVC-Hibernate/";
    ICustomerService proxy = null;

    @Before
    public void beforeClass(){
        ResteasyClient client = new ResteasyClientBuilder().build();
        ResteasyWebTarget target = client.target(UriBuilder.fromPath(path));
        proxy = target.proxy(ICustomerService.class);
    }

    @Test
    public void testGetallcustomer() throws Exception {
        CustomerListType customers = proxy.getAllCustomerInfo();
        List<CustomerType> customerTypes = customers.getCustomerType();
        for (CustomerType customerType : customerTypes) {
            System.out.println("----------------------------------------------------");
            System.out.println("Name       : "+customerType.getName());
            System.out.println("Age        : "+customerType.getAge());
            System.out.println("CustomerId : "+customerType.getCustomerId());
        }
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41310699

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档