JsonConverter implements Serializable { public byte[] writeValueAsBytes(Object value) { try { return jsonMapper.writeValueAsBytes(value); } catch (JsonProcessingException 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 writeValueAsBytes_test() { ConverterTestDto converterTestDto = new ConverterTestDto(); converterTestDto.setValue("dummy"); byte[] bytes = jsonConverter.writeValueAsBytes(converterTestDto); assertThat(Base64UrlUtil.encodeToString(bytes)).isEqualTo("eyJ2YWx1ZSI6ImR1bW15In0"); }
@Test void writeValueAsBytes_with_invalid_dto_test() { ConverterTestInvalidDto converterTestInvalidDto = new ConverterTestInvalidDto(); converterTestInvalidDto.setValue(new Object()); assertThrows(UncheckedIOException.class, () -> jsonConverter.writeValueAsBytes(converterTestInvalidDto) ); }