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

关于枚举反序列化失败的问题 #1319

Closed
Leeforrest opened this issue Jul 12, 2017 · 2 comments
Closed

关于枚举反序列化失败的问题 #1319

Leeforrest opened this issue Jul 12, 2017 · 2 comments
Milestone

Comments

@Leeforrest
Copy link

Leeforrest commented Jul 12, 2017

你好,我最近遇到一种情况是这样的,当类属性是枚举类型且是一个接口类型时,序列化后的字符串无法反序列化。我使用版本是1.2.34, 不知道是否有什么办法可以应对这种情况
我贴个例子:

public class GSTest {

    @JSONType(seeAlso = {MyEnum.class})
    interface EnumInterface{
        
    }
    @JSONType(typeName = "myEnum")
    enum MyEnum implements EnumInterface {
        Test1,
        Test2
    }
    @JSONType(typeName = "other")
    enum OtherEnum implements EnumInterface {
        Other
    }
    static class MyTest{
        private int value;
        private EnumInterface myEnum;

        public MyTest() {
        }

        public MyTest(int property, MyEnum enumProperty) {
            this.value = property;
            this.myEnum = enumProperty;
        }
        public int getValue() {
            return value;
        }
        public EnumInterface getMyEnum() {
            return myEnum;
        }
        public void setMyEnum(EnumInterface myEnum) {
            this.myEnum = myEnum;
        }
        public void setValue(int value) {
            this.value = value;
        }
    }
    
	public static void main(String[] args) {
        MyTest test = new MyTest(1, MyEnum.Test1);
        String result = JSON.toJSONString(test, SerializerFeature.WriteClassName);
        System.out.println(result);
        test = JSON.parseObject(result, MyTest.class);
        System.out.println(test);
    }
}
@wenshao
Copy link
Member

wenshao commented Jul 16, 2017

问题已经修复,请使用新版本
https://github.com/alibaba/fastjson/releases/tag/1.2.35

@wenshao wenshao closed this as completed Jul 16, 2017
@Leeforrest
Copy link
Author

太棒了,致敬

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants