public void populate(Object instance, DBObject from) {
try {
Field field = Fields.find(instance.getClass(), name());
field.setAccessible(true);
ParameterizedType elementType = (ParameterizedType) field.getGenericType();
Converter childMapper = context().converterFor((Class<?>) elementType.getActualTypeArguments()[0]);
BasicDBList list = (BasicDBList) from.get(name());
if (list != null) {
Collection collection = (Collection) field.get(instance);
for (Object o : list) {
//noinspection unchecked
collection.add(childMapper.fromDbValue(o));
}
}
field.setAccessible(false);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);