0

I'm developing a project using Opendaylight (oxygen-sr4). I defined objects by Yang. .yang file like: grouping person{ leaf enName{ type string; } leaf zhName{ type string; } }

When I transmit a person object to the front-end, I found field missing issue if the value of field is null. I need: {"person":{"enName":"allen","zhName":null}}, but i got: {"person":{"enName":"allen"}})

I debugged the project. I found the issue is when serializing the person object(Person.java is generated automatically by Yang),DataNodeContainerSerializerSource under module mdsal-binding-dom-codec
generated anonymous serialize method and added the null checking like this:

java.lang.String getZhName = ((java.lang.String) _input.getZhName());
if (getZhName != null) {
    _stream.leafNode("zhName",getZhName);
} 

org.opendaylight.mdsal.binding.dom.codec.gen.impl.DataNodeContainerSerializerSource generated anonymous serialize method:

private void emitChild(final StringBuilder sb, final String getterName, final Type childType,
            final DataSchemaNode schemaChild) {
        sb.append(statement(assign(childType, getterName, cast(childType, invoke(INPUT, getterName)))));

        sb.append("if (").append(getterName).append(" != null) {\n");
        emitChildInner(sb, getterName, childType, schemaChild);
        sb.append("}\n");
    }

Is there any way to transmit null value field? By modifying configuration of .yang file? Or by creating customize class that extends DataNodeContainerSerializerSource?

Btw, I found DataNodeContainerSerializerSource is deprecated now.

ghoultf
  • 1
  • 3
  • Try with `{"person":{"enName":"allen","zhName":[null]}}`. That is how empty values should be [encoded in JSON for data modeled with YANG](https://tools.ietf.org/html/rfc7951#section-6.9). – predi Jun 12 '19 at 14:30
  • Thanks for your comment @predi. Field type change to `Boolean` when changed the `.yang` file to `leaf zhName{ type empty; }`. I can not transmit string value any more(when the zhName is not null). @predi – ghoultf Jun 13 '19 at 01:31
  • Then this is probably a non-standard implementation. Wouldn't be a first for ODL. I don't use ODL, so can't help, sorry. – predi Jun 13 '19 at 06:18

0 Answers0