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

一个继承异常类,包含枚举值时,反序列化失败。 #3217

@eric-wang95

Description

@eric-wang95
@Test
    public void testException(){
        MyException myException = new MyException();
        myException.enumTest = EnumTest.FIRST;
        TestClass testClass = new TestClass();
        testClass.setMyException(myException);

        String jsonString = JSON.toJSONString(testClass,SerializerFeature.NotWriteDefaultValue);
        System.out.println(jsonString);

        TestClass testClass1 = JSON.parseObject(jsonString, TestClass.class);
        System.out.println(testClass1);
    }
    public static enum EnumTest{
        FIRST("111","111"),
        SECOND("222","222");
        private String key;
        private String value;

        EnumTest(String key, String value) {
            this.key = key;
            this.value = value;
        }

        public String getKey() {
            return key;
        }

        public void setKey(String key) {
            this.key = key;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }
    }

    public static class MyException extends Exception{
        private EnumTest enumTest;

        public EnumTest getEnumTest() {
            return enumTest;
        }

        public void setEnumTest(EnumTest enumTest) {
            this.enumTest = enumTest;
        }
    }
    public static class TestClass{
        private MyException myException;

        public MyException getMyException() {
            return myException;
        }

        public void setMyException(MyException myException) {
            this.myException = myException;
        }
    }

JDK:1.8.0_161
fastjson:1.2.61

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