无法捕获JsonMappingException

Web*_*net 10 java jackson

我的IDE给了我错误Unhandled Exception com.fasterxml.jackson.databind.JsonMappingExceptionmapper.readValue

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;
Run Code Online (Sandbox Code Playgroud)

我试过捕捉JsonMappingException它,但它没有让错误消失.有什么想法吗?

小智 6

当我只添加jackson-mapper-asljar 时,我遇到了这个问题.当我添加jackson-core-asljar时它起作用了.

杰克逊2也是如此.如果您只包括,则会发生此错误jackson-databind.你也需要包括在内jackson-core.


Sta*_*Man 2

JsonMappingExceptionextends IOException,所以你的 IDE 本身有一些更深层次的问题——也许库导入被搞乱了?