BUG 2667 : Handle null value type
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / datastore / node / utils / serialization / ValueSerializer.java
index 71946b0a7abe476241e3f1775ffa8e110da1d559..9e3230a623855d4add4249d68af0c2c216f4d79f 100644 (file)
@@ -16,6 +16,8 @@ import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessa
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 
 public class ValueSerializer {
+    private static final String NULL_VALUE = "";
+
     public static void serialize(NormalizedNodeMessages.Node.Builder builder,
             QNameSerializationContext context, Object value) {
         builder.setIntValueType(ValueType.getSerializableType(value).ordinal());
@@ -35,8 +37,10 @@ public class ValueSerializer {
                     }
                 }
             }
-        } else if(value instanceof byte[]){
+        } else if(value instanceof byte[]) {
             builder.setBytesValue(ByteString.copyFrom((byte[]) value));
+        } else if(value == null){
+            builder.setValue(NULL_VALUE);
         } else {
             builder.setValue(value.toString());
         }
@@ -64,6 +68,8 @@ public class ValueSerializer {
             }
         } else if(value instanceof byte[]){
             builder.setBytesValue(ByteString.copyFrom((byte[]) value));
+        } else if(value == null){
+            builder.setValue(NULL_VALUE);
         } else {
             builder.setValue(value.toString());
         }