BUG-706 Ignore anyxml nodes in binding serializer 97/22097/2
authorMaros Marsalek <mmarsale@cisco.com>
Mon, 8 Jun 2015 12:39:02 +0000 (14:39 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 9 Jun 2015 08:41:19 +0000 (08:41 +0000)
AnyXml is not supported on that level and currently leads to null pointer ex.

Change-Id: I5c2a64ab9502e4bba02efd822d2b5294ef456cef
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
code-generator/binding-data-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/gen/impl/DataNodeContainerSerializerSource.java

index 4d52dab58deefab413fd78cd50a82ff7f8c2cc53..45c1be0b10c47eebbe8d45cb64f9e684abab30d1 100644 (file)
@@ -31,9 +31,13 @@ import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 abstract class DataNodeContainerSerializerSource extends DataObjectSerializerSource {
 
+    private static final Logger LOG = LoggerFactory.getLogger(DataNodeContainerSerializerSource.class);
+
     protected static final String INPUT = "_input";
     private static final String CHOICE_PREFIX = "CHOICE_";
 
@@ -128,6 +132,19 @@ abstract class DataNodeContainerSerializerSource extends DataObjectSerializerSou
             if (!schemaChild.isAugmenting()) {
                 final String getter = getGetterName(schemaChild);
                 final Type childType = getterToType.get(getter);
+                if (childType == null) {
+                    // FIXME AnyXml nodes are ignored, since their type cannot be found in generated bindnig
+                    // Bug-706 https://bugs.opendaylight.org/show_bug.cgi?id=706
+                    if (schemaChild instanceof AnyXmlSchemaNode) {
+                        LOG.warn("Node {} will be ignored. AnyXml is not yet supported from binding aware code." +
+                                "Binding Independent code can be used to serialize anyXml nodes.", schemaChild.getPath());
+                        continue;
+                    } else {
+                        throw new IllegalStateException(
+                                String.format("Unable to find type for child node %s. Expected child nodes: %s",
+                                        schemaChild.getPath(), getterToType));
+                    }
+                }
                 emitChild(b, getter, childType, schemaChild);
             }
         }