JsonListConverter implements AttributeConverter<List, String> { @Override public List convertToEntityAttribute(final String value) { try { if (value == null) { return Collections.emptyList(); } return serializer.readValue(value, List.class); } catch (final IOException e) { log.error("Unable to parse value to 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 shouldConvertStringToEntityAttribute() { JsonListConverter converter = new JsonListConverter(); List list = converter.convertToEntityAttribute("[\"element_1\",\"element_2\"]"); assertEquals(list.size(), 2); }
@Test public void shouldConvertLongToEntityAttribute() { JsonListConverter converter = new JsonListConverter(); List list = converter.convertToEntityAttribute("[1,2]"); assertEquals(list.size(), 2); }