I've been playing with the MongoInputFormat that allows having all documents in a MongoDB collection put through a MapReduce job written in Hadoop.
As you can see in the provided examples (this, this and this) the type the document is in that is provided to the mapper is a BSONObject (an Interface in Java).
Now I also like Morphia very much which allows mapping the raw data from MongoDB into POJOs that are much easier to use.
Since I can only get a BSONObject as input I thought about using the method described at the bottom of this page of the Morphia wiki:
BlogEntry blogEntry = morphia.fromDBObject(BlogEntry.class, blogEntryDbObj);
My problem is that this method requires a DBObject instead of a BSONObject. A DBObject is really:
public interface DBObject extends BSONObject
So as you can see I cannot simply cast from BSONObject to DBObject and call the provided method.
How do I handle this the best way?
You'll notice that the
BSONObject
andDBObject
interfaces are very similar. Just because a converson doesn't exist doesn't mean it's not easy to create a trivial one:Now, you just need to