nutzam / nutz

Nutz -- Web Framework(Mvc/Ioc/Aop/Dao/Json) for ALL Java developer
https://nutzam.com
Apache License 2.0
2.53k stars 942 forks source link

Mirror Enum Bug #1488

Closed lihongjie0209 closed 5 years ago

lihongjie0209 commented 5 years ago
class ResidentStatusTest {

    @JsonShape(JsonShape.Type.NAME)
    public enum ResidentStatus {

        Init(){
            @Override
            public void apply() {
                throw new RuntimeException("resident.apply.init");
            }
        },
        Confirm(){
            @Override
            public void apply() {
                throw new RuntimeException("resident.apply.exist");
            }

            @Override
            public void confirmRoommate() {
                throw new RuntimeException("resident.apply.confirm.conformed");

            }
        },
        Reject(){
            @Override
            public void confirmRoommate() {
                throw new RuntimeException("resident.apply.confirm.rejected");

            }
        };

        public void apply() {

        }

        public void confirmRoommate() {

        }
    }

    @Test
    void testIsEnum() {

        ResidentStatus init = ResidentStatus.Init;

        Mirror<ResidentStatus> me = Mirror.me(init);

        Assertions.assertTrue(me.isEnum());

    }
}

结果:

org.opentest4j.AssertionFailedError: expected: <true> but was: <false>

    at org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:38)
    at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:40)
    at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:35)
    at org.junit.jupiter.api.Assertions.assertTrue(Assertions.java:137)
    at cn.boolin.entity.resident.ResidentStatusTest.testIsEnum(ResidentStatusTest.java:58)
    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.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:532)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:115)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:167)
    at org.junit.jupiter.engine.execution.ThrowableCollector.execute(ThrowableCollector.java:40)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:163)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:110)
    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:57)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.lambda$execute$3(HierarchicalTestExecutor.java:83)
    at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:77)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.lambda$null$2(HierarchicalTestExecutor.java:92)
    at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
    at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
lihongjie0209 commented 5 years ago

使用的是nb

<nutzboot.version>2.2-SNAPSHOT</nutzboot.version>
wendal commented 5 years ago

内部类??

lihongjie0209 commented 5 years ago

@wendal 不是 只是为了方便展示, 本地环境是单独的类,测试也没有通过

wendal commented 5 years ago
    @Test
    public void test_IsEnum() {

        ResidentStatus init = ResidentStatus.Init;

        Mirror<ResidentStatus> me = Mirror.me(init);

        System.out.println(init.getClass().isEnum());

        Assert.assertTrue(me.isEnum());

    }

好像真不是枚举

wendal commented 5 years ago

System.out.println打印的就是false

lihongjie0209 commented 5 years ago

@wendal 我发现这个问题主要是因为json序列化的时候没办法控制了。@JsonShape 失效,有什么解决方案吗?还是这是Json的一个BUG

wendal commented 5 years ago

我不知道怎么判断出是个枚举, 这是JDK8/9/10的新语法??

wendal commented 5 years ago
org.nutz.lang.util.ResidentStatusTest$ResidentStatus$1

事实上是个枚举类的内部类

lihongjie0209 commented 5 years ago

@wendal 我之前用的好好的, 不知道为什么现在Json表现异常了?

wendal commented 5 years ago

修改了一下, 应该好了

lihongjie0209 commented 5 years ago

@wendal ok 辛苦了