added handling of ObjectId fields

This commit is contained in:
Thomas Risberg
2010-12-01 20:41:58 -05:00
parent 4f4d93f41e
commit 77189f169a

View File

@@ -256,7 +256,8 @@ public class SimpleMongoConverter implements MongoConverter {
else { else {
logger.warn("Unable to map compound DBObject field " logger.warn("Unable to map compound DBObject field "
+ keyToUse + " to property " + pd.getName() + keyToUse + " to property " + pd.getName()
+ ". Should have been a 'DBObject' but was " + value.getClass().getName()); + ". The field value should have been a 'DBObject.class' but was "
+ value.getClass().getName());
} }
} }
else { else {
@@ -312,11 +313,18 @@ public class SimpleMongoConverter implements MongoConverter {
protected void setObjectIdOnObject(BeanWrapper bw, PropertyDescriptor pd, protected void setObjectIdOnObject(BeanWrapper bw, PropertyDescriptor pd, ObjectId value) {
ObjectId value) {
// TODO strategy for setting the id field. suggest looking for public // TODO strategy for setting the id field. suggest looking for public
// property 'Id' or private field id or _id; // property 'Id' or private field id or _id;
if (String.class.isAssignableFrom(pd.getPropertyType())) {
bw.setPropertyValue(pd.getName(), value);
}
else {
logger.warn("Unable to map _id field "
+ " to property " + pd.getName()
+ ". Should have been a 'String' property but was "
+ pd.getPropertyType().getName());
}
} }
protected boolean isValidProperty(PropertyDescriptor descriptor) { protected boolean isValidProperty(PropertyDescriptor descriptor) {