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

@BsonIgnore doesn't prevent PojoBuilderHelper.configureClassModelBuilder from calling getTypeData on ignored fields

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.6.0
    • Affects Version/s: 3.5.0
    • Component/s: POJO
    • None

      In a POJO if you have a field or method that is marked with @BsonIgnore , and if this is a type disallowed by the TypeData$Builder the class model creation will fail - despite this field / method not being required.

      Example exception

      java.lang.IllegalStateException: Invalid Map type. Maps MUST have string keys, found class com.TestEnum instead.
      	at org.bson.codecs.pojo.TypeData$Builder.validate(TypeData.java:117)
      	at org.bson.codecs.pojo.TypeData$Builder.build(TypeData.java:104)
      	at org.bson.codecs.pojo.PojoBuilderHelper.getTypeData(PojoBuilderHelper.java:158)
      	at org.bson.codecs.pojo.PojoBuilderHelper.configureClassModelBuilder(PojoBuilderHelper.java:87)
      	at org.bson.codecs.pojo.ClassModelBuilder.<init>(ClassModelBuilder.java:59)
      	at org.bson.codecs.pojo.ClassModel.builder(ClassModel.java:63)
      	at org.bson.codecs.pojo.PojoCodecProvider.createClassModel(PojoCodecProvider.java:194)
      	at org.bson.codecs.pojo.PojoCodecProvider.access$100(PojoCodecProvider.java:38)
      	at org.bson.codecs.pojo.PojoCodecProvider$Builder.build(PojoCodecProvider.java:115)
      

      Here the pojo contains a Map keyed on an enum. This map is marked with @BsonIgnore, hence I would not expect the failure above.

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            edwaki Kieron Edwards
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: