Add PojoCodec support for discriminator look ups on interfaces / abstract classes

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: POJO
    • None
    • Java Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      Add MongoCollection<Interface> / MongoCollection<Abstract Class> support by allowing the PojoCodec to detect discriminator support.

      Interface:

      @BsonDiscriminator
      public interface Pet {
          String getType();
      }
      
      public class Cat implements Pet {
      
          private String name;
          // ...
      }
      
      MongoCollection<Pet>.find() throws:
      Cannot find a public constructor for 'Pet'.  Please ensure the class has a public, empty constructor with no arguments, or else a constructor with a BsonCreator annotation
      

      Abstract classes

      @BsonDiscriminator
      public abstract class Pet {
          abstract String getType();
      }
      
      public class Cat extends Pet {
      
          private String name;
          // ...
      }
      
      MongoCollection<Pet>.insertOne(cat) and MongoCollection<Pet>.find() throws: 
      Can't find a codec for CodecCacheKey{clazz=class tour.Pet, types=null}.
      

      These usecases could be supported as the PojoCodec could detect @BsonDiscrim inator support.

              Assignee:
              Unassigned
              Reporter:
              Ross Lawley
              None
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated: