Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate org.codehaus.jackson.map.JsonMappingException:无法从START\u对象标记中反序列化java.util.ArrayList的实例_Hibernate_Resteasy - Fatal编程技术网

Hibernate org.codehaus.jackson.map.JsonMappingException:无法从START\u对象标记中反序列化java.util.ArrayList的实例

Hibernate org.codehaus.jackson.map.JsonMappingException:无法从START\u对象标记中反序列化java.util.ArrayList的实例,hibernate,resteasy,Hibernate,Resteasy,我已经开发了一个SpringMVC+RestEasy+Hibernate示例,并希望使用Junit对其进行测试,但看到以下错误:我还可以通过jsp或rest客户端调用这些web服务 org.jboss.resteasy.spi.ReaderException: org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT

我已经开发了一个SpringMVC+RestEasy+Hibernate示例,并希望使用Junit对其进行测试,但看到以下错误:我还可以通过jsp或rest客户端调用这些web服务

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测试:

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());

    }
}
公共类客户测试{
静态最终字符串ROOT_URL=”http://localhost:8080/RestEasy-Spring MVC Hibernate/resteasy/“;
@试验
public void testGetallcustomer()引发异常{
ClientRequest请求=新的ClientRequest(ROOT_URL+“customerservice/getallcustomer”);
ClientResponse response=request.get(新的GenericType(){});
List customers=response.getEntity();
System.out.println(“SIZE:+customers.SIZE());
}
}
此外,API似乎已被弃用:


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

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());
        }
    }
}
公共类客户测试{
最终字符串路径=”http://localhost:8080/RestEasy-Spring MVC Hibernate/”;
icCustomerService代理=null;
@以前
类()之前的公共无效{
ResteasyClient客户端=新的ResteasyClientBuilder().build();
ResteasyWebTarget=client.target(UriBuilder.fromPath(path));
proxy=target.proxy(icCustomerService.class);
}
@试验
public void testGetallcustomer()引发异常{
CustomerListType customers=proxy.getAllCustomerInfo();
List customerTypes=customers.getCustomerType();
for(CustomerType CustomerType:customerTypes){
System.out.println(“------------------------------------------------------------”);
System.out.println(“Name:+customerType.getName());
System.out.println(“年龄:+customerType.getAge());
System.out.println(“CustomerId:+customerType.getCustomerId());
}
}
}

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

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());
        }
    }
}
公共类客户测试{
最终字符串路径=”http://localhost:8080/RestEasy-Spring MVC Hibernate/”;
icCustomerService代理=null;
@以前
类()之前的公共无效{
ResteasyClient客户端=新的ResteasyClientBuilder().build();
ResteasyWebTarget=client.target(UriBuilder.fromPath(path));
proxy=target.proxy(icCustomerService.class);
}
@试验
public void testGetallcustomer()引发异常{
CustomerListType customers=proxy.getAllCustomerInfo();
List customerTypes=customers.getCustomerType();
for(CustomerType CustomerType:customerTypes){
System.out.println(“------------------------------------------------------------”);
System.out.println(“Name:+customerType.getName());
System.out.println(“年龄:+customerType.getAge());
System.out.println(“CustomerId:+customerType.getCustomerId());
}
}
}