Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-2800

ChangeStreamDocumentCodec unable to decode POJO using PojoCodecProvider configured with automatic(true)

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.6.4, 3.7.0
    • Affects Version/s: 3.6.3
    • Component/s: POJO

      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)
      

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            sanjay.gianchandani@mongodb.com Sanjay Gianchandani
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: