The short answer is: if you are dealing with IO, you are dealing with IOExceptions. If you are not dealing with IO, then you IOExceptionshould turn it into excluded exceptions, because they are signs of an erroneous code.
Longer answer:
readValuealways accepts JsonParser, which can be wrapped around I / O (such as a file or URL). If you are dealing with IO, there is no way to deal with IOExceptions, and you must either process them or transfer / transfer them somehow. Anything can happen during I / O, and you should be prepared to handle exceptions.
, , JsonParser IO (, JsonFactory#createJsonParser(java.lang.String) JSON ), , IOException, , , , . - :
ObjectMapper om = new ObjectMapper();
JsonParser jp = JsonFactory.createJsonParser("{ \"foo\": \"bar\" }");
try {
return om.readValue(jp);
} catch (IOException e) {
throw new AssertionError("An IOException occurred when this was assumed to be impossible.");
}
Nota bene: Java , , .
AssertionError throws, . , java.lang.RuntimeException java.lang.Error . , , , , - VM .
user824425