Customer was trying to use MongoCollection#watch feature with a POJO for a document class, and got an exception.
Reproduced (by Jeff Yemin) with a registry through this code:
ChangeStreamIterable<Person> changeStream = collection
.withCodecRegistry(fromRegistries(
collection.getCodecRegistry(),
fromProviders(PojoCodecProvider.builder().automatic(true).build())))
.withDocumentClass(Person.class)
.watch()
.fullDocument(UPDATE_LOOKUP);}}}}
Causes:
Exception in thread "Thread-1" org.bson.codecs.configuration.CodecConfigurationException: An exception occurred when decoding using the AutomaticPojoCodec. Decoding into a 'ChangeStreamDocument' failed with the following exception: ChangeStreamDocument contains generic types that have not been specialised. Top level classes with generic types are not supported by the PojoCodec. A custom Codec or PojoCodec may need to be explicitly configured and registered to handle this type. at org.bson.codecs.pojo.AutomaticPojoCodec.decode(AutomaticPojoCodec.java:40) at com.mongodb.client.model.changestream.ChangeStreamDocumentCodec.decode(ChangeStreamDocumentCodec.java:66) at com.mongodb.client.model.changestream.ChangeStreamDocumentCodec.decode(ChangeStreamDocumentCodec.java:36) at org.bson.RawBsonDocument.decode(RawBsonDocument.java:166) at com.mongodb.operation.ChangeStreamBatchCursor.convertResults(ChangeStreamBatchCursor.java:123) at com.mongodb.operation.ChangeStreamBatchCursor.access$000(ChangeStreamBatchCursor.java:33) at com.mongodb.operation.ChangeStreamBatchCursor$2.apply(ChangeStreamBatchCursor.java:68) at com.mongodb.operation.ChangeStreamBatchCursor$2.apply(ChangeStreamBatchCursor.java:65) at com.mongodb.operation.ChangeStreamBatchCursor.resumeableOperation(ChangeStreamBatchCursor.java:131) at com.mongodb.operation.ChangeStreamBatchCursor.next(ChangeStreamBatchCursor.java:65) at com.mongodb.MongoBatchCursorAdapter.next(MongoBatchCursorAdapter.java:56) at com.mongodb.MongoIterableImpl.first(MongoIterableImpl.java:87) at org.mongodb.test.three_six.ChangeStreamSamplePojoTest.lambda$main$0(ChangeStreamSamplePojoTest.java:79)