I have a model classes like
public class MyClass extends ReflectionDBObject {
private List<NiceAttribute> attributes;
...
}
public class NiceAttribute extends ReflectionDBObject {
...
}
I create it in a typesafe way, like
List<NiceAttribute> attrs = new ArrayList<NiceAttribute>();
attrs.add(new NiceAttribute());
MyClass myClass = new MyClass();
myClass.setAttributes(attrs);
then save it to mongo, and retrieve with a code like
DBCollection col = ...;
col.setObjectClass(MyClass.class)
MyClass foundObject = (MyClass)col.findOne();
But the problem is that foundObject
's attributes
becomes a list of BasicDBObject
. Looks like a driver can not (or does not want to) detect a list items type. Is this a driver limitation, or I missed something? What would be an elegant workaround for the problem?
BTW, I know about Morphia etc. Maybe it solves the problem. But my project is tiny, and I don't want to complicate things having one more layer of abstraction.