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

@BsonIgnore doesn't always work

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 3.11.0
    • Affects Version/s: 3.10.1
    • Component/s: BSON, POJO
    • Labels:
      None

      I have a POJO that I want to save, with the following methods:

       

      @BsonIgnore
      public String getSecret() {
        return secret;
      }
      
      @BsonIgnore 
      public void setSecret(String secret) { 
        this.secret = secret; 
      } 
       
      @BsonIgnore 
      public void setSecret(Integer i) { 
        this.secret = ""+i; 
      }
      

      This causes an error: 

      org.bson.codecs.configuration.CodecConfigurationException: Property 'secret' in TestListing, has differing data types: TypeData{type=String} and TypeData{type=Integer}

      If I change the last method name to "setSecretAsInt", I get this error:

      Unable to get value for property 'secretAsInt' in TestListing

      I can make it work if I then add a dummy getter like this:

       

      public Integer getSecretAsInt() { 
       return null; 
      }
      

      But that's just ugly, and shouldn't be necessary. If a property is marked as ignored, then the serialization code should ignore it, period.

      Similar bug (already fixed): https://jira.mongodb.org/browse/JAVA-2620

       

       

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            mike@iseecars.com Mike Baranczak
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: