Revert "Do not emit empty lists to NormalizedNodes" 71/84571/2
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 22 Sep 2019 02:12:42 +0000 (04:12 +0200)
committerRobert Varga <nite@hq.sk>
Sun, 22 Sep 2019 03:16:50 +0000 (03:16 +0000)
This reverts commit cbe6a8cafaec862f2a918ecc9af99720090d3c8a,
as it is breaing DTO behavior applications explicitly depend on.

The issue cannot be fixed without touching templates, i.e. requires
complete implementation of MDSAL-449.

JIRA: MDSAL-456
Change-Id: I07baf3a7be3867c6bee1b66a05b013ee0ba5171f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/DataObjectStreamer.java
binding/mdsal-binding-dom-codec/src/test/java/org/opendaylight/mdsal/binding/dom/codec/test/AugmentationSubstitutionTest.java
binding/mdsal-binding-dom-codec/src/test/java/org/opendaylight/mdsal/binding/dom/codec/test/NormalizedNodeSerializeDeserializeTest.java
binding/mdsal-binding-test-model/src/main/java/org/opendaylight/mdsal/binding/test/model/util/ListsBindingUtils.java

index 2f2ed8db4b8568227aff19c59373d88056cb823d..59ca8b0b8cb2e37e37259e6a9c17b8eef6b76579 100644 (file)
@@ -136,9 +136,8 @@ public abstract class DataObjectStreamer<T extends DataObject> implements DataOb
     protected static final <E extends DataObject> void streamList(final Class<E> childClass,
             final DataObjectStreamer<E> childStreamer, final DataObjectSerializerRegistry registry,
             final BindingStreamEventWriter writer, final List<? extends E> value) throws IOException {
-        final int size = nullSize(value);
-        if (size != 0) {
-            writer.startUnkeyedList(childClass, size);
+        if (value != null) {
+            writer.startUnkeyedList(childClass, value.size());
             commonStreamList(registry, writer, childStreamer, value);
         }
     }
@@ -146,9 +145,8 @@ public abstract class DataObjectStreamer<T extends DataObject> implements DataOb
     protected static final <E extends DataObject & Identifiable<?>> void streamMap(final Class<E> childClass,
             final DataObjectStreamer<E> childStreamer, final DataObjectSerializerRegistry registry,
             final BindingStreamEventWriter writer, final List<? extends E> value) throws IOException {
-        final int size = nullSize(value);
-        if (size != 0) {
-            writer.startMapNode(childClass, size);
+        if (value != null) {
+            writer.startMapNode(childClass, value.size());
             commonStreamList(registry, writer, childStreamer, value);
         }
     }
@@ -156,9 +154,8 @@ public abstract class DataObjectStreamer<T extends DataObject> implements DataOb
     protected static final <E extends DataObject & Identifiable<?>> void streamOrderedMap(final Class<E> childClass,
             final DataObjectStreamer<E> childStreamer, final DataObjectSerializerRegistry registry,
             final BindingStreamEventWriter writer, final List<? extends E> value) throws IOException {
-        final int size = nullSize(value);
-        if (size != 0) {
-            writer.startOrderedMapNode(childClass, size);
+        if (value != null) {
+            writer.startOrderedMapNode(childClass, value.size());
             commonStreamList(registry, writer, childStreamer, value);
         }
     }
@@ -207,8 +204,4 @@ public abstract class DataObjectStreamer<T extends DataObject> implements DataOb
     private static <T extends DataObject> boolean tryCache(final BindingStreamEventWriter writer, final T value) {
         return writer instanceof BindingSerializer ? ((BindingSerializer<?, T>) writer).serialize(value) == null : true;
     }
-
-    private static int nullSize(final List<?> list) {
-        return list == null ? 0 : list.size();
-    }
 }
index 6f3a2cb121a685542db41c6c6d1db9ec4bab1dce..144a5b4d9a0a26eb7e3b2a84e47289fb2e173898 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.mdsal.binding.dom.codec.test;
 
 import static org.junit.Assert.assertEquals;
 
+import java.util.Collections;
 import java.util.Optional;
 import org.junit.Test;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.RpcComplexUsesAugment;
@@ -73,6 +74,7 @@ public class AugmentationSubstitutionTest extends AbstractBindingCodecTest {
                 .setContainerWithUses(new ContainerWithUsesBuilder()
                     .setLeafFromGrouping("foo")
                     .build())
+                .setListViaUses(Collections.emptyList())
                 .build();
     }
 }
index a5ed9879fb881e0d513533fc166a905a06c9a2de..731ce67c7037123786c6cd326532848b7c77c727 100644 (file)
@@ -137,7 +137,7 @@ public class NormalizedNodeSerializeDeserializeTest extends AbstractBindingCodec
     private static ContainerNode getEmptyTop() {
         return ImmutableContainerNodeBuilder.create()
                     .withNodeIdentifier(new NodeIdentifier(TOP_QNAME))
-                    .build();
+                    .withChild(mapNodeBuilder(TOP_LEVEL_LIST_QNAME).build()).build();
     }
 
     private static final QName AGUMENT_STRING_Q = QName.create(TOP_QNAME, "augmented-string");
index c3d0490cc5027f31c5911906b4bdb892150f3c0a..f2e72f76cfa5d3321f7e3f75e04e680a5b16ef33 100644 (file)
@@ -58,10 +58,6 @@ public final class ListsBindingUtils {
         return path(key).augmentation(augmentation);
     }
 
-    public static Top top() {
-        return new TopBuilder().build();
-    }
-
     public static Top top(final TopLevelList... listItems) {
         return new TopBuilder().setTopLevelList(Arrays.asList(listItems)).build();
     }