BasicDBObject dbObject = context.getObjectToConvert();
if (dbObject == null) {
return null;
}
EntityInfo entityInfo = mongoStoreImpl.getEntityInfo(expectedEntityType);
S entity;
try {
entity = expectedEntityType.newInstance();
} catch (Exception e) {
throw new RuntimeException(e);
}
for (String key : dbObject.keySet()) {
Object value = dbObject.get(key);
Property<Object> property;
if ("_id".equals(key)) {
// Current property is "id"
if (entity instanceof MongoIdentifiableEntity) {
((MongoIdentifiableEntity)entity).setId(value.toString());
}
} else if ((property = entityInfo.getPropertyByName(key)) != null) {
// It's declared property with @DBField annotation
setPropertyValue(entity, value, property);
} else {
// Show warning if it's unknown