JsonUtil { public static <T> T deserialize(String jsonString, Class<T> klass) throws IOException { return objectMapper.readValue(jsonString, klass); }  static T treeToValue(JsonNode jsonNode, Class<T> klass); static T treeToValueNoException(JsonNode jsonNode, Class<T> klass); static T treeToValueNoException(JsonNode jsonNode, TypeReference<?> valueTypeRef); static JsonNode toJsonNode(Object object); static T deserialize(String jsonString, Class<T> klass); static T deserialize(URL url, Class<T> klass); static T deserializeNoException(String jsonString, Class<T> klass); static String serializeNoException(Object object); static String serialize(Object object); static ArrayNode createArrayNode(); static JsonNode readTree(String string);  }
@Test public void testDeserialize() throws IOException { String jsonString = "{\"id\":\"id\", \"method\":\"method\", \"params\":[]}"; JsonRpcV1Request request = new JsonRpcV1Request("id", "method"); assertEquals( request, JsonUtil.deserialize(jsonString, JsonRpcV1Request.class) ); String tmpFile = "tempfile"; Path file = Paths.get(tmpFile); Files.write(file, Collections.singletonList(jsonString)); assertEquals( request, JsonUtil.deserialize(file.toUri().toURL(), JsonRpcV1Request.class) ); Files.delete(file); assertNull(JsonUtil.deserializeNoException("{}", JsonRpcV1Request.class)); }