Mongo Java Driver 3 - Using an object extending 'Document'
<p>Mongo Java Driver 3 added support for the <a href="http://mongodb.github.io/mongo-java-driver/3.0/bson/codecs/" rel="nofollow">Codec infrastructure</a>, which I'm trying below.  By default it comes with codecs for the following 3 objects: Document, BasicDBObject and BsonDocument.</p>

<p>I'm trying to do something quite simple by having my class, MyClass, extend Document.  However it fails with the error as indicated inline.</p>

<p>I found this <a href="https://gist.github.com/cada9eaac3e24ef5a62a" rel="nofollow">gist</a> but it seems overly complex.. is there not a simple way to register MyClass as a Codec since it's also a Document?</p>

<p>Thank you.
-henning</p>

<pre><code>public class PlayMongo {
    static class MyClass extends Document {
        public MyClass(String key, Object value) {
            super(key, value);
        }
    }

    public static void main(String[] args) {
        MongoClient mongoClient = new MongoClient();
        MongoDatabase db = mongoClient.getDatabase("test");

        // Works like a charm
        MongoCollection&lt;Document&gt; documentCollection = db.getCollection("docs");
        documentCollection.insertOne(new Document().append("hello", "world"));

        // Fails with CodecConfigurationException: Can't find a codec for class play.reactivemongo.PlayMongo$MyClass
        MongoCollection&lt;MyClass&gt; myClassCollection = db.getCollection("myclasses", MyClass.class);
        myClassCollection.insertOne(new MyClass("hello", "world"));
    }
}
</code></pre>