Hi,
Let's assume we have the following POJO:
public final class Person { private final String name; private final Country country; @BsonCreator public Person( @BsonProperty("name") String name, @BsonProperty("country") Country country) { this.name = name; this.country = country; } @BsonId public String getName() { return name; } public Country getCountry() { return country; } public enum Country { IRELAND, POLAND } }
Now we create a related collection:
MongoCollection<Person> collection = new MongoClient() .getDatabase("database") .getCollection("people", Person.class) .withCodecRegistry(fromRegistries( getDefaultCodecRegistry(), fromProviders( PojoCodecProvider .builder() .automatic(true) // note the automatic POJO support .build() ) ));
Everything is fine when you do simple CRUD operations. But try to do the following:
Person person = collection
.find(eq("country", POLAND))
.first();
You will get org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class com.gat.lib.mongo.Person$Country
In such cases you need to register an enum codec manually. I think it's confusing, especially as the documentation says that "enums are fully supported" while they are limited to simple CRUD.