无法捕获JsonMappingException
我的IDE使用mapper.readValue
行给出了错误Unhandled Exception com.fasterxml.jackson.databind.JsonMappingException
错误
ObjectMapper mapper = new ObjectMapper(); try { if (response.isEmpty()) { //Http 204 (No Content) returned from MCC //We should handle this differently user = new User(); } else { user = mapper.readValue(response, User.class); } } catch (IOException ioe) { logger.log(Level.SEVERE, ioe.getLocalizedMessage()); } return user;
我已经尝试捕获JsonMappingException
但它没有使错误消失。 有什么想法吗?
JsonMappingException
扩展了IOException
,因此你的IDE有一些更深层次的麻烦 – 也许库导入搞砸了?
当我只添加jackson-mapper-asl
jar时,我遇到了这个问题。 当我添加jackson-core-asl
jar时它起作用了。
jackson2也是如此。 如果您只包含jackson-databind
则会发生此错误。 你还需要包括jackson-core
。
我遇到过同样的问题。 似乎JsonMappingException
类inheritance的类不在JAR文件中。 我刚刚恢复到没有问题的1.9版本。
我有同样的问题,当我加入json-core时 ,它对我有用 !
我遇到了同样的问题,因为org.codehaus.jackson.map.JsonMappingException扩展了JsonProcessingException(不是任何直接的Throwable),并且包中缺少这个。 在做了一些研究后,我直接下载了jar(不是Maven)并手动将它们添加到classpatch中:
- jackson的注解 – 2.1.2
- com.fasterxml.jackson.core
- com.fasterxml.jackson.databind
这3个包的组合解决了这个问题。
你也尝试过这个吗?
user = mapper.readValue(response.getEntity(String.class),User.class);
PS:假设, response
的类型为com.sun.jersey.api.client.ClientResponse
。
添加jackson-core-asl.jar,它会工作