[JAVA-2800] ChangeStreamDocumentCodec unable to decode POJO using PojoCodecProvider configured with automatic(true) Created: 05/Mar/18  Updated: 28/Oct/23  Resolved: 07/Mar/18

Status: Closed
Project: Java Driver
Component/s: POJO
Affects Version/s: 3.6.3
Fix Version/s: 3.6.4, 3.7.0

Type: Bug Priority: Major - P3
Reporter: Sanjay Gianchandani Assignee: Ross Lawley
Resolution: Fixed Votes: 0
Labels: java
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related

 Description   

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)



 Comments   
Comment by Githook User [ 07/Mar/18 ]

Author:

{'email': 'ross.lawley@gmail.com', 'name': 'Ross Lawley', 'username': 'rozza'}

Message: Fix ChangeStreamDocumentCodec registry order

Previously, prevented the use of automatic codecs.

JAVA-2800
Branch: 3.6.x
https://github.com/mongodb/mongo-java-driver/commit/89cbb64f511164696168790616324ad9e905065f

Comment by Githook User [ 07/Mar/18 ]

Author:

{'email': 'ross.lawley@gmail.com', 'name': 'Ross Lawley', 'username': 'rozza'}

Message: Fix ChangeStreamDocumentCodec registry order

Previously, prevented the use of automatic codecs.

JAVA-2800
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/4c5678984e317a52ae89e05508cce1e5c619dfd1

Comment by Ross Lawley [ 05/Mar/18 ]

This is occurs when using an automatic PojoCodecProvider, the current workaround is to explictly declare your classes / packages with the PojoCodecProvider rather than using the automatic.

Generated at Thu Feb 08 08:58:06 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.