I have model classes like
public class MyClass extends ReflectionDBObject {
private List<NiceAttribute> attributes;
...
}
public class NiceAttribute extends ReflectionDBObject {
...
}
I create it as a type e.g.
List<NiceAttribute> attrs = new ArrayList<NiceAttribute>();
attrs.add(new NiceAttribute());
MyClass myClass = new MyClass();
myClass.setAttributes(attrs);
then save it in mongo and get with a code like
DBCollection col = ...;
col.setObjectClass(MyClass.class)
MyClass foundObject = (MyClass)col.findOne();
But the problem is what foundObject attributesbecomes a list BasicDBObject. It seems that the driver cannot (or does not want) detect the type of list items. Is this a limitation for the driver, or am I missing something? What would be an elegant way to solve the problem?
By the way, I know about Morphia, etc. Maybe this solves the problem. But my project is tiny, and I donβt want to complicate things that have another layer of abstraction.
source
share