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

Add support for type in JSONWire #322

Closed peter-lawrey closed 3 years ago

RobAustin commented 3 years ago

I'm not sure it is working for this test case.

    public static class One extends SelfDescribingMarshallable {
        String text;

        public One(String text) {
            this.text = text;
        }
    }

    public static class Two extends SelfDescribingMarshallable {
        String text;

        public Two(String text) {
            this.text = text;
        }
    }

    public static class Three extends SelfDescribingMarshallable {
        private One one;
        private Two two;

        public Three() {
        }

    }

    @Test
    public void supportTypes2() {
        final Three three = new Three();
        three.one = new One("hello");
        three.two = new Two("world");

        JSONWire wire = new JSONWire(Bytes.allocateElasticOnHeap())
                .outputTypes(true);
        wire.getValueOut()
                .object(three);

        System.out.println(wire.bytes());

    }

it produces this: which has no type, for one and two


{"@net.openhft.chronicle.wire.JSON322Test$Three":{"one":{"text":"hello"},
"two":{"text":"world"}
}}
``
RobAustin commented 3 years ago

So the types are missing because they are inferred. so if we created this class

   public static class Four extends Two {
        String text;

        public Four(String text) {
            super(text);
            this.text = text;
        }
    }

and changed two to use type Four, it is not inferred and produces this ( below ), which is a bit inconsistent,... I mean it's hard to know where to get the data from because it may or may not be nested.

{"@net.openhft.chronicle.wire.JSON322Test$Three":{"one":{"text":"hello"},
"two":{"@net.openhft.chronicle.wire.JSON322Test$Four":{"text":"world"}}  }}
hft-team-city commented 3 years ago

Released in Chronicle-Wire-2.22ea5, BOM-2.22ea33

hft-team-city commented 2 years ago

Released in Chronicle-Wire-2.22ea11, BOM-2.22ea69