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

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

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

      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 Unassigned
            Reporter:
            ross@mongodb.com Ross Lawley
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: