Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
eric-wang95 opened this issue Jun 1, 2020 · 5 comments
Closed
Milestone

Comments

@eric-wang95
Copy link

eric-wang95 commented Jun 1, 2020

@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

@eric-wang95
Copy link
Author

`com.alibaba.fastjson.JSONException: set property error, TestFormat$MyException#enumTest

at com.alibaba.fastjson.parser.deserializer.FieldDeserializer.setValue(FieldDeserializer.java:162)
at com.alibaba.fastjson.parser.deserializer.ThrowableDeserializer.deserialze(ThrowableDeserializer.java:149)
at com.alibaba.fastjson.parser.deserializer.FastjsonASMDeserializer_1_TestClass.deserialze(Unknown Source)
at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:284)
at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:682)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:383)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:287)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:560)
at TestFormat.testException(TestFormat.java:147)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)

Caused by: java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.alibaba.fastjson.parser.deserializer.FieldDeserializer.setValue(FieldDeserializer.java:110)
... 33 more

Disconnected from the target VM, address: '127.0.0.1:59414', transport: 'socket'

Process finished with exit code -1
`

@wenshao wenshao modified the milestones: 1.2.72, 1.2.73 Jun 22, 2020
@wenshao wenshao reopened this Jul 26, 2020
@wenshao wenshao modified the milestones: 1.2.73, 1.2.74 Jul 26, 2020
@wenshao wenshao modified the milestones: 1.2.74, 1.2.75 Oct 8, 2020
@wenshao wenshao modified the milestones: 1.2.75, 1.2.76 Nov 5, 2020
@ShuningWan
Copy link

这个问题什么时候解决,有预计时间么

@ShuningWan
Copy link

@wenshao

@Certseeds
Copy link
Contributor

@ShuningWan @wenshao
Is there anyone had done something in this issue?
I am willing to solve it in a few months.

@long-forgotten
Copy link

@wenshao +1

@wenshao wenshao closed this as completed in 275da29 Apr 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants