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(value = true) 枚举反序列化未生效 #1435

Closed
leshalv opened this issue May 5, 2023 · 2 comments
Closed

JSONField(value = true) 枚举反序列化未生效 #1435

leshalv opened this issue May 5, 2023 · 2 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@leshalv
Copy link

leshalv commented May 5, 2023

在具有实现接口的枚举上使用JSONField(value = true)注解,反序列化失效。

public interface BaseEnum {
    /**
     * 获取code
     *
     * @return {@link String}
     */
    String getCode();

    /**
     * 获取desc
     *
     * @return {@link String}
     */
    String getDesc();

}
public enum Type implements BaseEnum{
    X(101, "Big"),
    M(102, "Medium"),
    S(103, "Small");

    private final int code;
    private final String name;

    Type(int code, String name) {
        this.code = code;
        this.name = name;
    }

    @JSONField(value = true)
    public String getCode() {
        return String.valueOf(code);
    }

    public String getName() {
        return name;
    }
}

public class Bean1 {
    public Type type;
}

@Test
public void test1() {
    Bean1 bean = new Bean1();
    bean.type = Type.M;
    String str = JSON.toJSONString(bean);
    assertEquals("{\"type\":102}", str);
    Bean1 bean1 = JSON.parseObject(str, Bean1.class);
    assertEquals(bean.type, bean1.type);
}
@leshalv leshalv added the bug Something isn't working label May 5, 2023
@wenshao wenshao added this to the 2.0.30 milestone May 5, 2023
@wenshao wenshao added the fixed label May 5, 2023
@wenshao
Copy link
Member

wenshao commented May 6, 2023

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.30-SNAPSHOT/
帮忙用2.0.30-SNAPSHOT验证,2.0.30预计在周末(5月7日前)发布

@wenshao
Copy link
Member

wenshao commented May 6, 2023

@wenshao wenshao closed this as completed May 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

2 participants