JsonConverter implements Serializable { public <T> T readValue(String src, Class<T> valueType) { try { return jsonMapper.readValue(src, valueType); } catch (MismatchedInputException | JsonParseException e) { throw new DataConversionException(INPUT_MISMATCH_ERROR_MESSAGE, e); } catch (IOException e) { throw new UncheckedIOException(e); } } JsonConverter(ObjectMapper jsonMapper); T readValue(String src, Class<T> valueType); T readValue(InputStream src, Class<T> valueType); T readValue(String src, TypeReference<T> valueTypeRef); T readValue(InputStream src, TypeReference<T> valueTypeRef); byte[] writeValueAsBytes(Object value); String writeValueAsString(Object value);  }
@Test void readValue_test() { ConverterTestDto dto = jsonConverter.readValue("{\"value\":\"dummy\"}", ConverterTestDto.class); assertThat(dto.getValue()).isEqualTo("dummy"); }
@Test void readValue_with_invalid_json_test() { assertThrows(DataConversionException.class, () -> jsonConverter.readValue("{value:\"dummy\"}", ConverterTestDto.class) ); }
@Test void readValue_with_TypeReference_test() { ConverterTestDto dto = jsonConverter.readValue("{\"value\":\"dummy\"}", new TypeReference<ConverterTestDto>() {}); assertThat(dto.getValue()).isEqualTo("dummy"); }
@Test void readValue_with_invalid_json_and_TypeReference_test() { TypeReference<ConverterTestDto> typeReference = new TypeReference<ConverterTestDto>() {}; assertThrows(DataConversionException.class, () -> jsonConverter.readValue("{value:\"dummy\"}", typeReference) ); }