Best way to write generic factory in Java
When you see yourself going and editing the same function again and again to extend its functionality then thats a code smell. The problem is that whenever you add a type you have to add an if condition to your converter. So the conversion could be the class responsibility. in Java 8 you can use Suppliers for that and if you don't have Java 8 then Guava is your friend 

 Supplier&lt;DBObject&gt; convertToDBObject(){ // java 8 code
   Supplier&lt;DBObject&gt; supplier = ()-&gt; {
     BasicDBObject dbObject = new BasicDBObject();
     dbObject.append("age", this.getAge());
     dbObject.append("id", this.getId());
     return dbObject;
   } 
  return supplier;
 }


Or implement Guava suppliers anonymously if you running java 6 or 7.
You can add an interface for convertable things that your classes can implement.

interface DBObjectConvertable{
   Supplier&lt;DBObject&gt; convertToDBObject();
}


and by doing so your types will be responsible for converting to DBObject in their own ways. The code smell in your code is adding ifs to the factory.Suppliers are factories but in a declarative way, so instead of returning converted object immediately, I will return you a function that knows how to convert to MongoDB objects.