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.