Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

Failed to deserialize list property if property name is snake case #1647

@ldn0x7dc

Description

@ldn0x7dc

fastjson version: 1.2.42

POJO

@Setter
@Getter
@Accessors(chain = true)
@JSONType(naming = PropertyNamingStrategy.SnakeCase)
public class Params {

    private boolean withFields;

    private List<String> verificationIds;
}

Test Case

@org.junit.Test
    public void test() {
        Params params = new Params()
                .setVerificationIds(Arrays.asList(new String[]{"a", "b"}))
                .setWithFields(true);

        String json = JSON.toJSONString(params);
        log.debug(json);

        params = JSON.parseObject(json, Params.class);
        log.debug(JSON.toJSONString(params));
    }

log output

 - {"verification_ids":["a","b"],"with_fields":true}
 - {"with_fields":true}

As the log shows, the property verification_ids is lost.
I've figured out that if I change verification_ids to verifications(no camel) or annotate the property with @JSONField(name = "verification_ids") or change List to String[], then it works fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions