Opendaylight ODL java JSON XML binding problem

101 Views Asked by At

i'm using yang-tools of ODL to generate java classes from YANG models. My project is a vanilla JAVA so i'm working outside opendaylight framework.

Starting from the following YANG Interfaces class is generated with all of it's dependency

module openconfig-interfaces {
    namespace "http://openconfig.net/yang/interfaces";
    prefix "if";

    container interfaces {
        list interface {
            key "name";
            leaf name {
                type string;
            }
            container config {
                leaf enabled {
                    type boolean;
                }
            }
        }
    }
}

Now i expect that generated class can be idratated from XML or JSON and also that this class can be serialized in JSON or XML to use it with restconf or netconf for example, but i can't find a method to do this.

I've started whit this super simple code

        Path path = Paths.get("src/main/yang");
        EffectiveModelContext context = getYangContext(path.toString());
        assertTrue(context.findModule(Interfaces.QNAME.getModule()).isPresent());

        final var result = new NormalizationResultHolder();
        final var streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);

        InterfacesBuilder interfacesBuilder = new InterfacesBuilder()
                .setInterface(Map.of(
                        new InterfaceKey("GigabitEthernet1"),
                        new InterfaceBuilder()
                                .setName("GigabitEthernet1")
                                .setConfig(new ConfigBuilder()
                                        .setEnabled(true)
                                        .build())
                                .build()
                ));

        var interfaces = interfacesBuilder.build();

now i've found a way to serialize a NormalizedNode to XML (not json) ,but i can't find a way to transform generated classes to a NormalizedNode.

How can i do that? Thanks for any help

0

There are 0 best solutions below