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

serialization by field Convention

    XMLWordPrintableJSON

Details

    • Icon: New Feature New Feature
    • Resolution: Duplicate
    • Icon: Major - P3 Major - P3
    • None
    • 3.8.1
    • POJO
    • None
    • JDK 8, Windows 10

    Description

      When serializing a POJO the properties are identified by** getter methods, *setter methods and* fields. (see http://mongodb.github.io/mongo-java-driver/3.6/bson/pojos/)

      If the POJO impl. contains non standard getter e.g.

       
      public class SomeClass {
       
      private String someField1;
       
      private String someField2;
       
       
       
      public String getSomeField1(){
       
        return someField1;
       
      }
       
       
       
      public String getSomeField2(){
       
        return someField2;
       
      }
       
       
       
      public Integer getCalculation(){
        // return some calculated value
       
      }
       
      }
      
      

      a property "calculation" with some value will be serialized which is not intendet. Sure, you can use some @BsonIgnore annotation to avoid that but you have to check the serialization bahaviour every time the POJO is extended by some get*() method. 

      Another issue is when integrating a given POJO with large amount of such non-standard get*() methods.

      It would be a great benefit to register some Convention which says: "serialize only the fields and ignore getter methods".

       

      Attachments

        Activity

          People

            ross@mongodb.com Ross Lawley
            vitali Vitali Pankraz
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: