RestEasy:org.codehaus.jackson.map.JsonMappingException:無法從START_OBJECT令牌(..)中反序列化java.util.ArrayList
這看起來像杰克遜(Jackson)錯誤,它期望解析一個數(shù)組(以“ [”開頭),但遇到一個對象(“{”)的開頭標記。通過查看您的代碼,我猜測它正在嘗試將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(..)
如何解決此問題?
相關文章:
1. javascript - 關于apply()與call()的問題2. javascript - JS變量被清空3. javascript - webpack 分割加載代碼后,react 界面不更新4. python 利用subprocess庫調(diào)用mplayer時發(fā)生錯誤5. datetime - Python如何獲取當前時間6. python文檔怎么查看?7. javascript - nginx反向代理靜態(tài)資源403錯誤?8. html - eclipse 標簽錯誤9. 安全性測試 - nodejs中如何防m(xù)ySQL注入10. java - 在用戶不登錄的情況下,用戶如何添加保存到購物車?
