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

Annotations example in Java driver POJO page seems incomplete

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 3.8.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      See http://mongodb.github.io/mongo-java-driver/3.7/bson/pojos/

      The Person example seems to be wrong. Doesn't the personId field need a @BsonId annotation? Also, maybe we could demonstrate the other annotations here just to be extra clear? Something like:

       

      import org.bson.codecs.pojo.annotations.*;
      
      @BsonDiscriminator
      public final class Person {
      
          @BsonId
          public String personId;
          public String firstName;
          @BsonProperty("surname")
          public String lastName; 
      
          @BsonIgnore
          public String password;
          
          @BsonProperty(useDiscriminator = true)
          public Address addr;
          
          public Person(){
          }
      
      }
      

      giving

      { "_id": "1234567890", "_t": "Person", "surname": "Alan", "lastName": "Turing",
        "address": { "_t": "Address", "address": "The Mansion", "street": "Sherwood Drive", "town": "Bletchley", "postcode": "MK3 6EB" } }

      Also weird capitalization in "The Person POJO *W*ill produce BSON similar to:"

       

       

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            nicholas.cottrell@mongodb.com Nic Cottrell
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: