Revert "Do not emit empty lists to NormalizedNodes" 72/84572/1
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 22 Sep 2019 02:12:42 +0000 (04:12 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 22 Sep 2019 02:13:43 +0000 (04:13 +0200)
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>
(cherry picked from commit f4f93bf1189e44a7e62a6c8396d7aa4fea03e5ca)

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 691a1ca3372ccc5e6c04a91e2b1552e2f3824439..9e652a558aad8b8d9971f8d4d52978d3a661955c 100644 (file)
@@ -140,9 +140,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);
         }
     }
@@ -150,9 +149,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);
         }
     }
@@ -160,9 +158,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);
         }
     }
@@ -211,8 +208,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();
     }