Skip to content
This repository has been 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

Closed
ldn0x7dc opened this issue Dec 13, 2017 · 2 comments
Closed

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

ldn0x7dc opened this issue Dec 13, 2017 · 2 comments
Labels
Milestone

Comments

@ldn0x7dc
Copy link

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.

@wenshao wenshao added the bug label Dec 14, 2017
@wenshao wenshao added this to the 1.2.43 milestone Dec 14, 2017
wenshao added a commit that referenced this issue Dec 16, 2017
@wenshao
Copy link
Member

wenshao commented Dec 16, 2017

https://github.com/alibaba/fastjson/releases/tag/1.2.43
问题已修复,请使用新版本

@wenshao wenshao closed this as completed Dec 16, 2017
wenshao added a commit that referenced this issue Jan 1, 2018
@logow
Copy link

logow commented Dec 6, 2018

今天也遇到了此问题,用的是1.2.28版本,经过不断的debug,找到了原因,准备提交 issue 了,发现新版本已修复了。

wenshao added a commit that referenced this issue Jul 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants