RestEasy:org.codehaus.jackson.map.JsonMappingException:無法從START_OBJECT令牌(..)中反序列化java.util.ArrayList
這看起來像杰克遜(Jackson)錯誤,它期望解析一個數組(以“ [”開頭),但遇到一個對象(“{”)的開頭標記。通過查看您的代碼,我猜測它正在嘗試將JSON反序列化到您的List中,但它正在獲取對象的JSON。
您的REST端點返回的JSON是什么樣的?它應該看起來像這樣
[ {// JSON for VariablePresentation value 0'field0': <some-value><etc...> }, <etc...>]解決方法
我有一個休息終點,它返回List<VariablePresentation>。我正在嘗試將此其余端點測試為
@Test public void testGetAllVariablesWithoutQueryParamPass() throws Exception {final ClientRequest clientCreateRequest = new ClientRequest('http://localhost:9090/variables');final MultivaluedMap<String,String> 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<VariablePresentation>> typeToken = new GenericType<List<VariablePresentation>>() {};final ClientResponse<List<VariablePresentation>> clientCreateResponse = clientCreateRequest.post(typeToken);assertEquals(201,clientCreateResponse.getStatus());final List<VariablePresentation> 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(..)
如何解決此問題?
相關文章:
