BUG 2325 : Value type of byte[] not recognized by the NormalizedNodeSerializer
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / datastore / node / utils / serialization / ValueSerializer.java
index 6a843f57c7718fb76911e90649b7194e3b6db0bb..aac45e18b5d7c420eeae0f6d47b62fdee6cb3078 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.controller.cluster.datastore.node.utils.serialization;
 
+import com.google.protobuf.ByteString;
 import org.opendaylight.controller.cluster.datastore.node.utils.QNameFactory;
 import org.opendaylight.controller.cluster.datastore.util.InstanceIdentifierUtils;
 import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
@@ -28,16 +29,18 @@ public class ValueSerializer {
                 InstanceIdentifierUtils.toSerializable((YangInstanceIdentifier) value, context));
         } else if(value instanceof Set) {
             Set set = (Set) value;
-            if(!set.isEmpty()){
-                for(Object o : set){
-                    if(o instanceof String){
+            if (!set.isEmpty()) {
+                for (Object o : set) {
+                    if (o instanceof String) {
                         builder.addBitsValue(o.toString());
                     } else {
                         throw new IllegalArgumentException("Expected value type to be Bits but was : " +
-                            value.toString());
+                                value.toString());
                     }
                 }
             }
+        } else if(value instanceof byte[]){
+            builder.setBytesValue(ByteString.copyFrom((byte[]) value));
         } else {
             builder.setValue(value.toString());
         }
@@ -57,6 +60,8 @@ public class ValueSerializer {
                     node.getInstanceIdentifierValue(), context);
         } else if(node.getIntValueType() == ValueType.BITS_TYPE.ordinal()){
             return new HashSet(node.getBitsValueList());
+        } else if(node.getIntValueType() == ValueType.BINARY_TYPE.ordinal()){
+            return node.getBytesValue().toByteArray();
         }
         return deSerializeBasicTypes(node.getIntValueType(), node.getValue());
     }