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 - vue2 的npm run dev 卡死... 网页无法打开. 8080端口没有被占用...2. node.js - vue-cll+sass 样式不出来 已经npm install sass、 sass-loader了3. 微信无法扫描phpqrcode生成的二维码4. javascript - 百度echarts图表如何修改5. index.php错误,求指点6. vim - docker中新的ubuntu12.04镜像,运行vi提示,找不到命名.7. 用PHP怎么在微信公众号里使用模板信息,公众号还未做开发?8. python2.7 - django 无法连接redis9. sqlserver - mysql如何查询多列重复的数据个数?10. python - 在ubuntu下安装scrapy过程遇到的问题
