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. node.js - mysql如何通過knex查詢今天和七天內的匯總數據2. mysql 插入數值到特定的列一直失敗3. 360瀏覽器與IE瀏覽器有何區別???4. Python從URL中提取域名5. mysql - 百萬行的表中是否盡量避免使用update等sql語句?6. python - 在使用Pycharm時經常看到如下的樣式,小括號里紅色的部分是什么意思呢?7. javascript - 新浪微博網頁版的字數限制是怎么做的8. 怎么在網頁中設置圖片進行左右滑動9. javascript - 豆瓣的這個自適應是怎么做的?10. javascript - 用jsonp抓取qq音樂總是說回調函數沒有定義
