OpenHFT / Chronicle-Wire

A Low Garbage Java Serialisation Library that supports multiple formats
http://chronicle.software
Apache License 2.0
513 stars 123 forks source link

Issue with serialising/de serialising typed JSON wire from and to a DailySessionSchedule #331

Closed RobAustin closed 2 years ago

RobAustin commented 3 years ago

This code [ chronicle fix has to be on the class path ]


        final DailySessionSchedule schedule = Marshallable.fromString("!software.chronicle.fix.staticcode.schedule.DailySessionSchedule {\n" +
                "  activeDays: [\n" +
                "    MONDAY,\n" +
                "    TUESDAY,\n" +
                "    WEDNESDAY,\n" +
                "    THURSDAY,\n" +
                "    FRIDAY\n" +
                "  ],\n" +
                "  startTime: 07:00,\n" +
                "  endTime: 17:00,\n" +
                "  sessionLength: !java.time.Duration PT10H,\n" +
                "  scheduleTimeZone: !java.time.ZoneRegion {\n" +
                "    id: Europe/London\n" +
                "  },\n" +
                "  periods: [\n" +
                "    !software.chronicle.fix.staticcode.schedule.DailySessionSchedule$Period { startDay: MONDAY, startTime: 07:00, endDay: MONDAY, endTime: 17:00 },\n" +
                "    !software.chronicle.fix.staticcode.schedule.DailySessionSchedule$Period { startDay: TUESDAY, startTime: 07:00, endDay: TUESDAY, endTime: 17:00 },\n" +
                "    !software.chronicle.fix.staticcode.schedule.DailySessionSchedule$Period { startDay: WEDNESDAY, startTime: 07:00, endDay: WEDNESDAY, endTime: 17:00 },\n" +
                "    !software.chronicle.fix.staticcode.schedule.DailySessionSchedule$Period { startDay: THURSDAY, startTime: 07:00, endDay: THURSDAY, endTime: 17:00 },\n" +
                "    !software.chronicle.fix.staticcode.schedule.DailySessionSchedule$Period { startDay: FRIDAY, startTime: 07:00, endDay: FRIDAY, endTime: 17:00 }\n" +
                "  ]\n" +
                "}\n");

        final JSONWire jsonWire = new JSONWire().useTypes(true);
        jsonWire.getValueOut().object(schedule);
        final Bytes<?> bytes = jsonWire.bytes();

        JSONWire jsonWire2 = new JSONWire().useTypes(true);
        jsonWire2.bytes().write(bytes);
        final Object object = jsonWire2.getValueIn().object();
        System.out.println(object);

throws the following exception :

Connected to the target VM, address: '127.0.0.1:49640', transport: 'socket'
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access using Lookup on net.openhft.chronicle.core.Jvm (file:/Users/robaustin/.m2/repository/net/openhft/chronicle-core/2.22ea10-SNAPSHOT/chronicle-core-2.22ea10-20211018.110148-4.jar) to class java.lang.reflect.AccessibleObject
WARNING: Please consider reporting this to the maintainers of net.openhft.chronicle.core.Jvm
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[main] INFO net.openhft.chronicle.core.Jvm - Chronicle core loaded from file:/Users/robaustin/.m2/repository/net/openhft/chronicle-core/2.22ea10-SNAPSHOT/chronicle-core-2.22ea10-20211018.110148-4.jar
[main] WARN net.openhft.chronicle.core.pool.ClassAliasPool - Did not replace by simpleName class software.chronicle.platform.fix.gui.endtoend.notifer.AcceptorMessageNotifier with class software.chronicle.platform.fix.gui.AppendWithMethodWriterTest$AcceptorMessageNotifier
[main] WARN net.openhft.chronicle.core.pool.ClassAliasPool - Did not replace by simpleName class software.chronicle.fix50sp2.generators.MessageGenerator with class software.chronicle.generated.code.generators.MessageGenerator
Oct 20, 2021 8:37:59 PM net.openhft.chronicle.core.cleaner.impl.reflect.ReflectionBasedByteBufferCleanerService <clinit>
WARNING: Make sure you have set the command line option "--illegal-access=permit --add-exports java.base/jdk.internal.ref=ALL-UNNAMED" to enable ReflectionBasedByteBufferCleanerService
[main] WARN net.openhft.chronicle.wire.WireMarshaller - Found this$0, in class software.chronicle.fix.staticcode.schedule.DailySessionSchedule$Period which will be ignored!
[main] WARN net.openhft.chronicle.wire.WireMarshaller$ObjectFieldAccess - Unable to parse field: sessionLength, as a marshallable as it is net.openhft.chronicle.core.io.IORuntimeException: Trying to read marshallable class java.time.Duration at [pos: 234, rlim: 1074, wlim: 8EiB, cap: 8EiB ] 0,⒑  endTime: 17:00,⒑  sessionLength: !java.time.Duration PT10H,ǁ⒑  scheduleTimeZone: !java.time.ZoneRegion {⒑    id: Europe/Lond... expected to find a {
net.openhft.chronicle.core.io.IORuntimeException: Trying to read marshallable class java.time.Duration at [pos: 234, rlim: 1074, wlim: 8EiB, cap: 8EiB ] 0,⒑  endTime: 17:00,⒑  sessionLength: !java.time.Duration PT10H,ǁ⒑  scheduleTimeZone: !java.time.ZoneRegion {⒑    id: Europe/Lond... expected to find a {
    at net.openhft.chronicle.wire.TextWire$TextValueIn.marshallable(TextWire.java:3181)
    at net.openhft.chronicle.wire.Wires.objectMap(Wires.java:479)
    at net.openhft.chronicle.wire.Wires.object0(Wires.java:559)
    at net.openhft.chronicle.wire.ValueIn.object(ValueIn.java:523)
    at net.openhft.chronicle.wire.WireMarshaller$ObjectFieldAccess.setValue(WireMarshaller.java:681)
    at net.openhft.chronicle.wire.WireMarshaller$FieldAccess.readValue(WireMarshaller.java:566)
    at net.openhft.chronicle.wire.WireMarshaller.readMarshallableDTOOrder(WireMarshaller.java:237)
    at net.openhft.chronicle.wire.WireMarshaller.readMarshallable(WireMarshaller.java:230)
    at net.openhft.chronicle.wire.Marshallable.readMarshallable(Marshallable.java:125)
    at net.openhft.chronicle.wire.SerializationStrategies$1.readUsing(SerializationStrategies.java:48)
    at net.openhft.chronicle.wire.TextWire$TextValueIn.marshallable(TextWire.java:3196)
    at net.openhft.chronicle.wire.Wires.objectMap(Wires.java:479)
    at net.openhft.chronicle.wire.Wires.object0(Wires.java:559)
    at net.openhft.chronicle.wire.ValueIn.object(ValueIn.java:523)
    at net.openhft.chronicle.wire.TextWire$TextValueIn.objectWithInferredType0(TextWire.java:3483)
    at net.openhft.chronicle.wire.TextWire$TextValueIn.objectWithInferredType(TextWire.java:3456)
    at net.openhft.chronicle.wire.ValueIn.object(ValueIn.java:517)
    at net.openhft.chronicle.wire.WireType$1.fromString(WireType.java:84)
    at net.openhft.chronicle.wire.Marshallable.fromString(Marshallable.java:58)
    at software.chronicle.platform.fix.gui.AppendWithMethodWriterTest.test(AppendWithMethodWriterTest.java:168)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    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.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    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:69)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)

java.lang.IllegalArgumentException: No enum constant java.time.DayOfWeek.{"@DayOfWeek":"MONDAY"}

    at java.base/java.lang.Enum.valueOf(Enum.java:240)
    at net.openhft.chronicle.core.pool.StaticEnumClass.valueOf(StaticEnumClass.java:37)
    at net.openhft.chronicle.core.pool.StaticEnumClass.valueOf(StaticEnumClass.java:27)
    at net.openhft.chronicle.core.pool.EnumInterner.intern(EnumInterner.java:65)
    at net.openhft.chronicle.wire.WireInternal.internEnum(WireInternal.java:99)
    at net.openhft.chronicle.wire.ValueIn.asEnum(ValueIn.java:495)
    at net.openhft.chronicle.wire.WireMarshaller$EnumSetFieldAccess.addAll(WireMarshaller.java:1016)
    at net.openhft.chronicle.wire.TextWire$TextValueIn.sequence(TextWire.java:2878)
    at net.openhft.chronicle.wire.WireMarshaller$EnumSetFieldAccess.readValue(WireMarshaller.java:970)
    at net.openhft.chronicle.wire.WireMarshaller.readMarshallableDTOOrder(WireMarshaller.java:237)
    at net.openhft.chronicle.wire.WireMarshaller.readMarshallable(WireMarshaller.java:230)
    at net.openhft.chronicle.wire.Marshallable.readMarshallable(Marshallable.java:125)
    at net.openhft.chronicle.wire.SerializationStrategies$1.readUsing(SerializationStrategies.java:48)
    at net.openhft.chronicle.wire.TextWire$TextValueIn.marshallable(TextWire.java:3196)
    at net.openhft.chronicle.wire.JSONWire$JSONValueIn.marshallable(JSONWire.java:369)
    at net.openhft.chronicle.wire.Wires.objectMap(Wires.java:479)
    at net.openhft.chronicle.wire.Wires.object0(Wires.java:559)
    at net.openhft.chronicle.wire.ValueIn.object(ValueIn.java:523)
    at net.openhft.chronicle.wire.JSONWire$JSONValueIn.parseType(JSONWire.java:434)
    at net.openhft.chronicle.wire.JSONWire$JSONValueIn.parseType(JSONWire.java:381)
    at net.openhft.chronicle.wire.JSONWire$JSONValueIn.object(JSONWire.java:343)
    at software.chronicle.platform.fix.gui.AppendWithMethodWriterTest.test(AppendWithMethodWriterTest.java:201)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    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.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    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:69)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)

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

Process finished with exit code 255
JerryShea commented 2 years ago

@RobAustin and @minborg, the use case where we de/serialise this class has gone, so this specifically is not a problem. I believe that we have improved de/serialisation of java.time.Duration with some other issues recently, and so I would bet that java.time.Duration is no longer a problem. Maybe we just need to add a unit test?

minborg commented 2 years ago

Closing this issue as I can confirm we are testing Duration:

image

This will print:

actual = {"@java.time.Duration":"PT1M3S"}
actual = "PT1M3S"
minborg commented 2 years ago

Thanks for pointing this out @JerryShea