CollectionMapper extends Mapper<Collection<T>> { @Override public Collection<T> fromDb(@Nullable final Object dbValue) throws MapperException { final Collection<?> collection; if (dbValue == null) { collection = Collections.emptyList(); } else if (dbValue instanceof Collection) { collection = (Collection<?>) dbValue; } else { collection = Collections.singletonList(dbValue); } final List<T> values = new ArrayList<>(); assert elementMapper != null; for (final Object elt : collection) { final T value = elementMapper.fromDb(elt); if (value != null) { values.add(value); } } return values; } protected  CollectionMapper(@Nullable final Class<? extends Mapper<T>> elementMapperType,
                               @Nullable final Mapper<T> elementMapper); @Nonnull static CollectionMapper<T> create(@Nonnull final Class<? extends Mapper<T>> elementMapperType); @Nonnull static CollectionMapper<T> create(@Nonnull final Mapper<T> elementMapper); @Nonnull Mapper<T> getElementMapper(); @Override Collection<T> fromDb(@Nullable final Object dbValue); @Nullable @Override List<Object> toDb(@Nullable final Collection<T> value);  }
@Test public void testFromDb() throws SchemaException, MapperException { LOG.info("testFromDb"); Collection<String> db = null; Collection<?> mem; mem = mapper.fromDb(db); Assert.assertTrue(mem != null); Assert.assertTrue(mem.isEmpty()); db = new ArrayList<>(); mem = mapper.fromDb(db); Assert.assertTrue(mem != null); Assert.assertTrue(mem.isEmpty()); db.add("red"); mem = mapper.fromDb(db); Assert.assertTrue(mem != null); Assert.assertTrue(mem.size() == 1); Assert.assertEquals("red", mem.toArray()[0]); db.add("blue"); mem = mapper.fromDb(db); Assert.assertTrue(mem != null); Assert.assertTrue(mem.size() == 2); Assert.assertEquals("red", mem.toArray()[0]); Assert.assertEquals("blue", mem.toArray()[1]); }