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

[BUG] JsonFormat 注解支持问题 #2836

Closed
aimilin6688 opened this issue Jul 29, 2024 · 4 comments
Closed

[BUG] JsonFormat 注解支持问题 #2836

aimilin6688 opened this issue Jul 29, 2024 · 4 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@aimilin6688
Copy link

问题描述

当设置 @jsonformat(shape = JsonFormat.Shape.OBJECT) 在枚举类上时,序列化正常,反序列化报错

环境信息

请填写以下信息:

  • OS信息: WIndows 11
  • JDK信息:jdk21
  • 版本信息:2.0.52

重现步骤

如何操作可以重现该问题:

public class FastJsonTest {
    @AllArgsConstructor
    @Getter
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum Type implements Serializable  {
        A("1", "1"), B("2","2"), C("3", "3");
        private final String code;
        private final String msg;
    }
    @AllArgsConstructor
    @Data
    public static class User implements Serializable {
        private String name;
        private Type type;
    }

    public static void main(String[] args) {
        JSONFactory.setUseJacksonAnnotation(true);
        String test = JSON.toJSONString(new User("test", Type.B));
        System.out.println(test);
        String jsonString = JSON.toJSONString(Type.A);
        System.out.println(jsonString);
        Type type = JSONObject.parseObject(jsonString, Type.class);
        System.out.println(type);
    }
}

附加信息

如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。

image

建议默认禁用jackson注解支持,否则会有很多意向不到的问题

@aimilin6688 aimilin6688 added the bug Something isn't working label Jul 29, 2024
@wenshao wenshao added this to the 2.0.53 milestone Aug 8, 2024
@wenshao wenshao added the fixed label Aug 8, 2024
@wenshao
Copy link
Member

wenshao commented Aug 8, 2024

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.53-SNAPSHOT/
问题已修复,序列化结果已经和jackson一致,这种情况jackson反序列化也是不支持的。

请帮忙用2.0.53-SNAPSHOT帮忙验证,2.0.53版本预计在月底发布

@acexy
Copy link

acexy commented Sep 12, 2024

mark 请问该问题是否已经解决或者可以自定义解码器来手动实现

@wenshao
Copy link
Member

wenshao commented Sep 13, 2024

问题已经修复,正式版本2.0.53将会在这个周末发布

@wenshao wenshao closed this as completed Sep 16, 2024
@wenshao
Copy link
Member

wenshao commented Sep 16, 2024

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

3 participants