Visitar URL original
@JSONField 枚举序列化 栈溢出 · Issue #3601 · alibaba/fastjson · GitHub
Skip to content
This repository was archived by the owner on Jul 29, 2026. It is now read-only.
This repository was archived by the owner on Jul 29, 2026. It is now read-only.

@JSONField 枚举序列化 栈溢出 #3601

Closed

Description

@linxinqiang90

版本:1.2.72,1.2.73,1.2.75
枚举中只有一个值,并且被@JSONField,序列化时溢出
枚举2个值以上,序列化正常。

@Data
public class TestEntity {
    private TestEnum testEnum;
    private String testName;
}
public enum TestEnum {
    @JSONField(name = "xx")
    test1("1");
//    @JSONField(name = "xx2")
//    test2("2");
    private String title;

    private TestEnum(String title) {
        this.title = title;
    }

}
   public static void main(String[] args) {
        TestEntity testEntity = new TestEntity();
        testEntity.setTestName("xxxx");
        testEntity.setTestEnum(TestEnum.test1);
        System.out.println(JSON.toJSONString(testEntity));
    }
Exception in thread "main" java.lang.StackOverflowError
	at com.alibaba.fastjson.JSON.getMixInAnnotations(JSON.java:1384)
	at com.alibaba.fastjson.serializer.SerializeConfig.get(SerializeConfig.java:878)
	at com.alibaba.fastjson.serializer.SerializeConfig.getObjectWriter(SerializeConfig.java:444)
	at com.alibaba.fastjson.serializer.SerializeConfig.getObjectWriter(SerializeConfig.java:440)
	at com.alibaba.fastjson.serializer.JSONSerializer.getObjectWriter(JSONSerializer.java:448)
	at com.alibaba.fastjson.serializer.JSONSerializer.write(JSONSerializer.java:309)
	at com.alibaba.fastjson.serializer.EnumSerializer.write(EnumSerializer.java:58)
	at com.alibaba.fastjson.serializer.JSONSerializer.write(JSONSerializer.java:312)
	at com.alibaba.fastjson.serializer.EnumSerializer.write(EnumSerializer.java:58)
	at com.alibaba.fastjson.serializer.JSONSerializer.write(JSONSerializer.java:312)

Activity

  1. github-ganyu commented on Jan 8, 2021

    @github-ganyu
    Contributor

    I fixed the bug and it has been merged into the master:
    2fa8ee0

  2. added this to the 1.2.76 milestone on Apr 5, 2021
  3. added a commit that references this issue on Jul 17, 2024
    b584203
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions