Skip to content

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

@aimilin6688

Description

@aimilin6688

问题描述

当设置 @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注解支持,否则会有很多意向不到的问题

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixed

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions