title: MongoDB: Register codecs (Java)
body: <p>I've been trying for about an hour now to register a codec I made for one of my classes in a game I am working on. The class is called <code>Item</code>. I tried the code and suggestions from these 3 places:</p>
  
  <ul>
  <li><a href="https://mongodb.github.io/mongo-java-driver/3.0/bson/codecs/" rel="noreferrer">https://mongodb.github.io/mongo-java-driver/3.0/bson/codecs/</a></li>
  <li><a href="https://matteosilvestri.blogspot.ca/2015/03/overview-of-pluggable-codecs-in-mongodb.html" rel="noreferrer">https://matteosilvestri.blogspot.ca/2015/03/overview-of-pluggable-codecs-in-mongodb.html</a></li>
  <li><a href="https://gist.github.com/JaiHirsch/cada9eaac3e24ef5a62a" rel="noreferrer">https://gist.github.com/JaiHirsch/cada9eaac3e24ef5a62a</a></li>
  </ul>
  
  <p>and here is the code I cam up with:</p>
  
  <pre><code>CodecRegistry defaultCodecRegistry = MongoClient.getDefaultCodecRegistry();
  MyCodecProvider myCodecProvider = new MyCodecProvider();
  ItemCodec itemCodec = new ItemCodec(defaultCodecRegistry);
  
  CodecRegistry codecRegistry = CodecRegistries.fromRegistries(CodecRegistries.fromCodecs(itemCodec), CodecRegistries.fromProviders(myCodecProvider), defaultCodecRegistry);;
  MongoClientOptions options = MongoClientOptions.builder().codecRegistry(codecRegistry).build();
  
  client = new MongoClient("localhost:27017", options);
  </code></pre>
  
  <p>So I built a Codec and codec provider called <code>MyCodecProvider</code>, so what am I doing wrong, how can this be so complicated? Am I missing something? It seems more complicated than it needs to be. If you need more code please ask. Thanks.</p>
  
  <p>Edit: The exact error I get is <code>org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class [Lnet.hollowbit.archipeloserver.items.Item;.</code> Also, I am trying to parse an Item array, do I need to make a codec specifically for the array too?</p>