JsonSetConverter implements AttributeConverter<Set, String> { @Override public Set convertToEntityAttribute(final String value) { try { if (value == null) { return Collections.emptySet(); } return serializer.readValue(value, Set.class); } catch (final IOException e) { log.error("Unable to parse value to Set - {}. Error - {}", value, e.getMessage(), e); throw new FabricManagerException(e); } } JsonSetConverter();  JsonSetConverter(final ObjectMapper serializer); @Override String convertToDatabaseColumn(final Set value); @Override Set convertToEntityAttribute(final String value);  }
@Test public void shouldConvertStringToEntityAttribute() { JsonSetConverter converter = new JsonSetConverter(); Set set = converter.convertToEntityAttribute("[\"element_1\",\"element_2\"]"); assertEquals(set.size(), 2); }
@Test public void shouldConvertLongToEntityAttribute() { JsonSetConverter converter = new JsonSetConverter(); Set set = converter.convertToEntityAttribute("[1,2]"); assertEquals(set.size(), 2); }