ViolationObjectConverter implements AttributeConverter<Object, String> { @Override public String convertToDatabaseColumn(final Object obj) { if (obj == null) { return null; } try { return objectMapper.writeValueAsString(obj); } catch (final JsonProcessingException e) { logger.info("Could not parse object metadata: {}. The value will be converted as string. Reason: {}", obj, e); return obj.toString(); } }  @Override String convertToDatabaseColumn(final Object obj); @Override Object convertToEntityAttribute(final String value);  }
@Test public void testConvertToDatabaseColumn() throws Exception { final Object obj = singletonMap("test","this is a test"); final String result = violationObjectConverter.convertToDatabaseColumn(obj); assertThat(result).isEqualTo("{\"test\":\"this is a test\"}"); }
@Test public void testConvertToDatabaseColumnNull() throws Exception { final Object obj = null; final String result = violationObjectConverter.convertToDatabaseColumn(obj); assertThat(result).isNull(); }