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

Allow @BsonProperty to set the write name on a field when no setter is available

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 3.10.0
    • Component/s: POJO
    • Labels:
      None

       

      public class WidgetDocument {
       
          private String ssn;
         
          @BsonProperty("ssn")
          public String getSSN() {
              return ssn;
          }
       
      }
      

      The PropertyModel for the field in the class above looks like:

      PropertyModel{propertyName='sSN', readName='ssn', writeName='sSN', typeData=TypeData{type=String}}
      

      Preferably I would expect propertyName="ssn". If that isn't an option than I would like to set the writeName="ssn" without the use of a setter.

      If I add a setter with the @BsonProperty it works as expected,

      @BsonProperty("ssn")
      public void setSSN(String ssn) {
          this.ssn = ssn;
      }
      

      This can be done by manually configuring the PropertyModel writeName via the ClassBuilder etc., but ideally this should be able to be configured via annotations. Could this be achieved by allowing a @BsonProperty annotation on a field to set the writeName?

       

       

       

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            etay2000 Eric Tray
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: