public static DBObject buildDBObject(JsonTreeNode rootNode) {
BasicDBObject basicDBObject = new BasicDBObject();
Enumeration children = rootNode.children();
while (children.hasMoreElements()) {
JsonTreeNode node = (JsonTreeNode) children.nextElement();
MongoKeyValueDescriptor descriptor = (MongoKeyValueDescriptor) node.getDescriptor();
Object value = descriptor.getValue();
if (value instanceof DBObject) {
if (value instanceof BasicDBList) {
basicDBObject.put(descriptor.getKey(), buildDBList(node));
} else {
basicDBObject.put(descriptor.getKey(), buildDBObject(node));
}
} else {
basicDBObject.put(descriptor.getKey(), value);
}
}
return basicDBObject;
}