CollectionMapper extends Mapper<Collection<T>> { @Nullable @Override public List<Object> toDb(@Nullable final Collection<T> value) throws MapperException { if (value == null) { return Collections.emptyList(); } assert elementMapper != null; final List<Object> dbObjects = new ArrayList<>(value.size()); for (final T v : value) { final Object dbValue = elementMapper.toDb(v); dbObjects.add(dbValue); } return dbObjects; } 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 testToDb() throws SchemaException, MapperException { LOG.info("testToDb"); List<?> db; Collection<String> mem = null; db = mapper.toDb(mem); Assert.assertTrue(db != null); Assert.assertTrue(db.isEmpty()); mem = new ArrayList<>(); db = mapper.toDb(mem); Assert.assertTrue(db != null); Assert.assertTrue(db.isEmpty()); mem.add("silver"); db = mapper.toDb(mem); Assert.assertTrue(db != null); Assert.assertTrue(db.size() == 1); Assert.assertEquals("silver", db.get(0)); mem.add("gold"); db = mapper.toDb(mem); Assert.assertTrue(db != null); Assert.assertTrue(db.size() == 2); Assert.assertEquals("gold", db.get(1)); }