Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

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

Closed
linxinqiang90 opened this issue Dec 24, 2020 · 1 comment
Closed

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

linxinqiang90 opened this issue Dec 24, 2020 · 1 comment
Milestone

Comments

@linxinqiang90
Copy link

linxinqiang90 commented Dec 24, 2020

版本: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)
@github-ganyu
Copy link
Contributor

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

@wenshao wenshao added this to the 1.2.76 milestone Apr 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants