Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@JSONField(deserialize = false)失效 #3163

Open
lilanlong opened this issue Nov 16, 2024 · 2 comments
Open

@JSONField(deserialize = false)失效 #3163

lilanlong opened this issue Nov 16, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@lilanlong
Copy link
Contributor

问题描述

@JSONField(deserialize = false)
public int id;
如果属性是用【public】修饰的,反序列化【deserialize = false】不起作用。

环境信息

请填写以下信息:

  • OS信息: Win11
  • JDK信息: 1.8
  • 版本信息:2.0.53
@lilanlong lilanlong added the bug Something isn't working label Nov 16, 2024
wenshao added a commit that referenced this issue Nov 21, 2024
@wenshao
Copy link
Member

wenshao commented Nov 21, 2024

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.annotation.JSONField;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class Issue3163 {
    @Test
    public void test() {
        Bean bean = JSON.parseObject("{\"id\":1234}", Bean.class);
        assertEquals(0, bean.id);
    }

    public static class Bean {
        @JSONField(deserialize = false)
        public int id;
    }
}

问题未重现

@lilanlong
Copy link
Contributor Author

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.annotation.JSONField;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class Issue3163 {
    @Test
    public void test() {
        Bean bean = JSON.parseObject("{\"id\":1234}", Bean.class);
        assertEquals(0, bean.id);
    }

    public static class Bean {
        @JSONField(deserialize = false)
        public int id;
    }
}

问题未重现

如果属性id有set方法,是必须在set方法上面加【@JSONField(deserialize = false)】才能生效吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants