Skip to content

BasicClassIntrospector.forSerialization(...).findProperties should respect MapperFeature.AUTO_DETECT_GETTERS/SETTERS #1223

@headw01

Description

@headw01

When I set the ObjectMapper MapperConfig to not AutoDetect and use the BasicClassIntrospector to get the properties, I seem to still be getting the Methods. I am currently using version 2.7.3.

The following code produces this output:
Found property count 2, there should only be one??
Found property: name=name, internalName=name
Found property: name=groupname, internalName=groupname

I think it should produce only this output:
Found property: name=groupname, internalName=groupname

public static void main(String [] args) {
    class TCls {
        @JsonProperty("groupname")
        private String groupname;

        public void setName(String str) {
            this.groupname = str;
        }
        public String getName() {
            return groupname;
        }
    }

    ObjectMapper om = new ObjectMapper();
    // Only use explicitly specified values to be serialized/deserialized (i.e., JSONProperty).
    om.configure(com.fasterxml.jackson.databind.MapperFeature.AUTO_DETECT_FIELDS, false);
    om.configure(com.fasterxml.jackson.databind.MapperFeature.AUTO_DETECT_GETTERS, false);
    om.configure(com.fasterxml.jackson.databind.MapperFeature.AUTO_DETECT_SETTERS, false);
    om.configure(com.fasterxml.jackson.databind.MapperFeature.AUTO_DETECT_IS_GETTERS, false);
    om.configure(com.fasterxml.jackson.databind.MapperFeature.USE_GETTERS_AS_SETTERS, false);
    om.configure(com.fasterxml.jackson.databind.MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);
    om.configure(com.fasterxml.jackson.databind.MapperFeature.INFER_PROPERTY_MUTATORS, false);
    om.configure(com.fasterxml.jackson.databind.MapperFeature.USE_ANNOTATIONS, true);

    JavaType javaType = om.getTypeFactory().constructType(TCls.class);

    BasicClassIntrospector introspector = new BasicClassIntrospector();
    BasicBeanDescription bdesc = introspector.forSerialization(om.getSerializationConfig(), javaType, null);
    List<BeanPropertyDefinition> bprops = bdesc.findProperties();

    if (1 != bprops.size()) {
        System.out.println("Found property count " + bprops.size() + ", there should only be one??");
    }
    bprops.forEach(prop -> {
        System.out.println("Found property: name=" + prop.getName() + ", internalName=" + prop.getInternalName());
    });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions