JsonListConverter implements AttributeConverter<List, String> { @Override public String convertToDatabaseColumn(final List value) { try { return serializer.writeValueAsString(value); } catch (final JsonProcessingException e) { log.error("Unable to parse list - {}. Error - {}", value, e.getMessage(), e); throw new FabricManagerException(e); } } JsonListConverter();  JsonListConverter(final ObjectMapper serializer); @Override String convertToDatabaseColumn(final List value); @Override List convertToEntityAttribute(final String value);  }
@Test public void shouldConvertStringToDatabaseColumn() { JsonListConverter converter = new JsonListConverter(); List<String> list = Lists.newArrayList(); list.add("element_1"); list.add("element_2"); assertEquals(converter.convertToDatabaseColumn(list), "[\"element_1\",\"element_2\"]"); }
@Test public void shouldConvertLongToDatabaseColumn() { JsonListConverter converter = new JsonListConverter(); List<Long> list = Lists.newArrayList(); list.add(1L); list.add(2L); assertEquals(converter.convertToDatabaseColumn(list), "[1,2]"); }