JacksonObjectMapper { public void checkValidJson(byte[] bytes) throws IOException { JsonParser parser = objectMapper.getFactory().createParser(bytes); while (parser.nextToken() != null) { } } JacksonObjectMapper(ObjectMapper objectMapper); T fromJson(byte[] bytes, Class<T> type); T fromJson(byte[] bytes, Class<T> type, Class<?> view); Map<String, String> fromJsonToMap(byte[] bytes); byte[] toJson(Object object); byte[] toJson(Object object, Class<?> serializationView); byte[] toJson(Map<String, String> map); byte[] toPrettyJson(Object object, Class<?> serializationView); String prettyPrint(Object object); String prettyPrint(String json); void checkValidJson(byte[] bytes); T assign(T target, byte[] source);  }
@Test(expected = JsonProcessingException.class) public void should_check_that_json_is_invalid() throws Exception { String notjson = "\n" + " \"fr-FR\": {\n" + " \"Default name\": \"Nom par défaut\",\n" + " \"Hello boys\": \"Coucou les garçooonns\"\n" + " },\n" + " \"ru-RU\": {\n" + " \"Default label\": \"Etiqueta por defecto\",\n" + " \"Hello boys\": \"Bonjourno los garçones\"\n" + " }\n" + "}"; objectMapper.checkValidJson(notjson.getBytes(StandardCharsets.UTF_8)); }
@Test public void should_check_that_json_is_valid() throws Exception { objectMapper.checkValidJson("{ \"collection\": [\n] }".getBytes(StandardCharsets.UTF_8)); objectMapper.checkValidJson("[1, 2, 3, 4]".getBytes(StandardCharsets.UTF_8)); String json = "{\n" + " \"fr-FR\": {\n" + " \"Default name\": \"Nom par défaut\",\n" + " \"Hello boys\": \"Coucou les garçooonns\"\n" + " },\n" + " \"ru-RU\": {\n" + " \"Default label\": \"Etiqueta por defecto\",\n" + " \"Hello boys\": \"Bonjourno los garçones\"\n" + " }\n" + "}"; objectMapper.checkValidJson(json.getBytes(StandardCharsets.UTF_8)); }