JsonUtil { public static Map<String, Object> convertJsonToMap(InputStream json) { return convertJsonToMap(json, new TypeReference<Map<String, Object>>() { }); } private  JsonUtil(); static Map<String, Object> convertJsonToMap(InputStream json); static Map<String, Object> convertJsonToMap(String json); static Map<K, V> convertJsonToMap(InputStream json, TypeReference<Map<K, V>> typeReference); static Map<K, V> convertJsonToMap(String json, TypeReference<Map<K, V>> typeReference); static List<Object> convertJsonToList(InputStream json); static List<Object> convertJsonToList(String json); static List<T> convertJsonToList(InputStream json, TypeReference<List<T>> typeReference); static List<T> convertJsonToList(String json, TypeReference<List<T>> typeReference); static byte[] toJsonBinary(Object object); static String toJson(Object object); static String toJson(Object object, boolean indentedOutput); static T fromJsonBinary(byte[] json, TypeReference<T> typeReference); static T fromJsonBinary(byte[] json, Class<T> classOfT); static T fromJson(String json, TypeReference<T> typeReference); static T fromJson(String json, Class<T> classOfT); static ObjectWriter getObjectWriter(boolean indentedOutput); static ObjectMapper getObjectMapper();  }
@Test void testConvertJsonToMapWithInvalidJsonInputStream() { String invalidJson = "{]"; InputStream invalidJsonInputStream = IOUtils.toInputStream(invalidJson, Charset.defaultCharset()); ParsingException resultException = Assertions.assertThrows(ParsingException.class, () -> JsonUtil.convertJsonToMap(invalidJsonInputStream)); String errorMessage = resultException.getCause() .getMessage(); ParsingException expectedException = new ParsingException(resultException.getCause(), Messages.CANNOT_CONVERT_JSON_STREAM_TO_MAP, errorMessage, invalidJsonInputStream); Assertions.assertEquals(expectedException.getMessage(), resultException.getMessage()); }
@Test void testConvertJsonToMapWithInvalidJsonString() { String invalidJson = "{]"; ParsingException resultException = Assertions.assertThrows(ParsingException.class, () -> JsonUtil.convertJsonToMap(invalidJson)); String errorMessage = resultException.getCause() .getMessage(); ParsingException expectedException = new ParsingException(resultException.getCause(), Messages.CANNOT_CONVERT_JSON_STRING_TO_MAP, errorMessage, invalidJson); Assertions.assertEquals(expectedException.getMessage(), resultException.getMessage()); }