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(..)
如何解決此問題?
相關文章:
1. css - 如何把一個視圖放在左浮動定位的視圖的上面?2. javascript - axios請求回來的數據組件無法進行綁定渲染3. php多任務倒計時求助4. python的正則怎么同時匹配兩個不同結果?5. javascript - vue中怎么使用原生js插件6. javascript - 請問下面代碼中的...是擴展運算符還是操作運算符?這樣寫是什么意思?7. javascript - 小demo:請教怎么做出類似于水滴不斷擴張的效果?8. css - 子元素跑到父元素外面9. MySQL的聯合查詢[union]有什么實際的用處10. javascript - jquery怎么讓a標簽跳轉后保持tab的樣式
