RestEasy:org.codehaus.jackson.map.JsonMappingException:无法从START_OBJECT标记(..)中反序列化java.util.ArrayList的实例

我有一个rest端点,它返回List 。 我试图测试这个rest端点为

  @Test public void testGetAllVariablesWithoutQueryParamPass() throws Exception { final ClientRequest clientCreateRequest = new ClientRequest("http://localhost:9090/variables"); final MultivaluedMap formParameters = clientCreateRequest.getFormParameters(); final String name = "testGetAllVariablesWithoutQueryParamPass"; formParameters.putSingle("name", name); formParameters.putSingle("type", "String"); formParameters.putSingle("units", "units"); formParameters.putSingle("description", "description"); formParameters.putSingle("core", "true"); final GenericType<List> typeToken = new GenericType<List>() { }; final ClientResponse<List> clientCreateResponse = clientCreateRequest.post(typeToken); assertEquals(201, clientCreateResponse.getStatus()); final List variables = clientCreateResponse.getEntity(); assertNotNull(variables); assertEquals(1, variables.size()); } 

此测试失败并显示错误

 org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token(..) 

我该如何解决这个问题?

这看起来像是一个Jackson错误,它期望解析一个数组(以'[‘开头),但它遇到一个对象的开始标记('{‘)。 从查看你的代码,我猜它正在尝试将JSON反序列化到你的List中,但是它获得了一个对象的JSON。

REST端点返回的JSON是什么样的? 应该看起来像这样

 [ { // JSON for VariablePresentation value 0 "field0":   },  ]