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. 關于docker下的nginx壓力測試2. docker images顯示的鏡像過多,狗眼被亮瞎了,怎么辦?3. java - 阿里的開發手冊中為什么禁用map來作為查詢的接受類?4. dockerfile - [docker build image失敗- npm install]5. nignx - docker內nginx 80端口被占用6. html5 - 使用echarts中的圖表 一個頁面導入了好幾個js圖表 實現echarts圖表隨著瀏覽器窗口變化而變化時出現了問題7. dockerfile - 我用docker build的時候出現下邊問題 麻煩幫我看一下9. docker api 開發的端口怎么獲???10. python3.x - git bash如何運行.bat文件?
