jackson-databind icon indicating copy to clipboard operation
jackson-databind copied to clipboard

UnKnownProperty in 2.13.3 and 2.18.5 (with property names like "uPhone", "uName")

Open impwang91 opened this issue 1 month ago • 6 comments

Search before asking

  • [x] I searched in the issues and found nothing similar.

Describe the bug

entity

@Getter
@Setter
public class UserInfoParam implements Serializable {

    private static final long serialVersionUID = 3841116001413160891L;

    private String uPhone;

    private String uName;

    private Byte sex;

    private Integer age;

    private Date createTime;

    private Date updateTime;

}

RequestBody

{
  "uName": "www",
  "uPhone": "13333333333",
  "age": 19,
  "sex": 1
}

The properties of age and sex is normal, but uName and uPhone failed, I have traced the invoke chain, find there is bug in com/fasterxml/jackson/core/jackson-databind/2.18.5/jackson-databind-2.18.5-sources.jar!/com/fasterxml/jackson/databind/deser/BeanDeserializer.java:396:, _beanProperties cant find uName, but have uname finally, I replace uName to userName, all worked.

Version Information

2.13.3 and 2.18.5

Environment

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.8</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

   ......
    <url/>
    <licenses>
        <license/>
    </licenses>
    <developers>
        <developer/>
    </developers>
    <scm>
        <connection/>
        <developerConnection/>
        <tag/>
        <url/>
    </scm>

    <properties>
        <java.version>11</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.18.5</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.18.5</version>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.42</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.16.0</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.3.0</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

impwang91 avatar Nov 23 '25 07:11 impwang91

Could you share with us the reproduction, @impwang91 ?

  • Actual Pojo declarations,
  • ObjectMapper instance configuration and everything
  • EXCLUDE anything not-Jackson like Lombok, Spring --this would help

JooHyukKim avatar Nov 23 '25 12:11 JooHyukKim

Could you share with us the reproduction, @impwang91 ?

  • Actual Pojo declarations,
  • ObjectMapper instance configuration and everything
  • EXCLUDE anything not-Jackson like Lombok, Spring --this would help

I have pasted Pojo and dependencies, except this, I did not change anything, everything is default.

impwang91 avatar Nov 23 '25 13:11 impwang91

Ah okay I thought it actually was bug report, but seems otherwise.

@impwang91 Try instead of @Getter @Setter, declare explicitly.

  • getUName()
  • setUName()
  • getUPhone()
  • setUPhone()

JooHyukKim avatar Nov 23 '25 17:11 JooHyukKim

@impwang91 If you can upgrade to 2.20.x (2.20.1), could try enabling MapperFeature.FIX_FIELD_NAME_UPPER_CASE_PREFIX which has a good chance of solving your issue (see #5152 for details if interested).

cowtowncoder avatar Nov 23 '25 21:11 cowtowncoder

Wrote reproduction #5447 for verification.

Succesfully deserialized IntelliJ-generated getter, setters, using Plain ObjectMapper.

public String getuPhone() { return uPhone;}
public String getuName() { return uName;}

but failed to deserialize when getter/setters were declared like below.

public getUPhone() { return uPhone;}
public String getUName() { return uName;}

Adding .enable(MapperFeature.FIX_FIELD_NAME_UPPER_CASE_PREFIX) did the trick, like @cowtowncoder suggested.

@impwang91 You may upgrade to 2.20 version to utiliaze MapperFeature.FIX_FIELD_NAME_UPPER_CASE_PREFIX

JooHyukKim avatar Nov 30 '25 15:11 JooHyukKim

Will leave open for now but likely close soon since solution/work-arounds exists and there seems to be no issue to fix.

cowtowncoder avatar Nov 30 '25 23:11 cowtowncoder