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

Added the Parsing of typed JSON wire #323

Closed RobAustin closed 2 years ago

RobAustin commented 3 years ago

issue https://github.com/OpenHFT/Chronicle-Wire/issues/322 introduces types to JSON wire, for example, the following code:


    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 output() {

        final Three three = new Three();
        three.one = new One("hello");
        three.two = new Two("world");

        JSONWire wire = new JSONWire(Bytes.allocateElasticOnHeap())
                .outputTypes(true);
        System.out.println(wire.getValueOut()
                .object(three));
    }

will output:

{"@net.openhft.chronicle.wire.JSON322Test$Three":{"one":{"@net.openhft.chronicle.wire.JSON322Test$One":{"text":"hello"}}, "two":{"@net.openhft.chronicle.wire.JSON322Test$Two":{"text":"world"}}  }}

The requirement for this task is to be able to parse the JSON ( above), back to the java object graph, hence the reciprocal of https://github.com/OpenHFT/Chronicle-Wire/issues/322 which produces the JSON.

Once Implemented, please write a one-page article on how to parse, typed java objects, to and from JSON. Please send this article to Carina and add it to chronicle wire docs.

peter-lawrey commented 2 years ago

What is outstanding on this?