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

@BsonIgnore doesn't always work

    XMLWordPrintable

    Details

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

      Description

      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

       

       

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: