Skip to content

Mapper in 3.0.0 does not match property with second letter capitalized to getter/setter for incompatible getter/setter (see #2882) #5355

@alexgrech4

Description

@alexgrech4

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

If a property with a capitalized second letter (i.e. String aProp;) has a getter/setter whose name has not changed the prop name (i.e. getaProp() and setaProp()) the property will not be properly serialized/deserialized. This is true whether or not the mapper feature MapperFeature.FIX_FIELD_NAME_UPPER_CASE_PREFIX is enabled or disabled.

Version Information

3.0.0

Reproduction

public class TestPojo {
    private String aProp;
    private String anotherProp;

    public String getaProp() {
        return aProp;
    }

    public void setaProp(String aProp) {
        this.aProp = aProp;
    }

    public String getAnotherProp() {
        return anotherProp;
    }

    public void setAnotherProp(String anotherProp) {
        this.anotherProp = anotherProp;
    }
}

public void featureEnabledTest() {

  ObjectMapper mapper = JsonMapper.builder().enable(MapperFeature.FIX_FIELD_NAME_UPPER_CASE_PREFIX).build();

  String json = "{\"aProp\":\"aPropValue\", \"prop1\":\"prop1Value\"}";
  TestPojo result = mapper.readValue(json, TestPojo.class);
  assert "aPropValue".equals(result.getaProp()); //fails

  String serialized = mapper.writeValueAsString(result);
  assert serialized.equals(json);
}

public void featureDisabledTest() {

  ObjectMapper mapper = JsonMapper.builder().disable(MapperFeature.FIX_FIELD_NAME_UPPER_CASE_PREFIX).build();

  String json = "{\"aProp\":\"aPropValue\", \"prop1\":\"prop1Value\"}";
  TestPojo result = mapper.readValue(json, TestPojo.class);
  assert "aPropValue".equals(result.getaProp()); //fails

  String serialized = mapper.writeValueAsString(result);
  assert serialized.equals(json);
}

Expected behavior

No response

Additional context

This was not an issue in 2.20.0, but has become one since migrating to 3.0.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    has-failing-testIndicates that there exists a test case (under `failing/`) to reproduce the issuewill-not-fixClosed as either non-issue or something not planned to be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions