ViolationObjectConverter implements AttributeConverter<Object, String> { @Override public Object convertToEntityAttribute(final String value) { if (StringUtils.hasText(value)) { try { return objectMapper.readValue(value, JsonNode.class); } catch (final IOException e) { logger.info("Could not parse value metadata: {}. The value will be converted as map. Reason: {}", value, e); return Collections.singletonMap("data", value); } } return null; }  @Override String convertToDatabaseColumn(final Object obj); @Override Object convertToEntityAttribute(final String value);  }
@Test public void testConvertToEntityAttribute() throws Exception { final String value = "{\"test\":\"this is a test\"}"; final Object result = violationObjectConverter.convertToEntityAttribute(value); assertThat(result).isEqualTo(objectMapper.readValue("{\"test\":\"this is a test\"}", JsonNode.class)); }
@Test public void testConvertToEntityAttributeEmpty() throws Exception { final String value = ""; final Object result = violationObjectConverter.convertToEntityAttribute(value); assertThat(result).isNull(); }