Order the annotation output

There is a slight worry of backward compatibility, however, Set does not
guarantee the order anyway. So, the northbound interface users could not
rely on any ordering. This means that making the order deterministic and
easily human readable just improves the situation without much
overhead.

Change-Id: I8a4de3ecac87a7499a107ad12c7a3038332868cd
diff --git a/cli/src/main/java/org/onosproject/cli/AbstractShellCommand.java b/cli/src/main/java/org/onosproject/cli/AbstractShellCommand.java
index 444631e..f83c5fa 100644
--- a/cli/src/main/java/org/onosproject/cli/AbstractShellCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/AbstractShellCommand.java
@@ -91,7 +91,8 @@
      */
     public static String annotations(Annotations annotations) {
         StringBuilder sb = new StringBuilder();
-        for (String key : annotations.keys()) {
+        Set<String> keys = new TreeSet<>(annotations.keys());
+        for (String key : keys) {
             sb.append(", ").append(key).append('=').append(annotations.value(key));
         }
         return sb.toString();
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/AnnotationsCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/AnnotationsCodec.java
index 754e24e..a155e3b 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/AnnotationsCodec.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/AnnotationsCodec.java
@@ -23,6 +23,9 @@
 import org.onosproject.net.DefaultAnnotations;
 import org.onosproject.net.DefaultAnnotations.Builder;
 
+import java.util.Set;
+import java.util.TreeSet;
+
 /**
  * Annotations JSON codec.
  */
@@ -31,7 +34,8 @@
     @Override
     public ObjectNode encode(Annotations annotations, CodecContext context) {
         ObjectNode result = context.mapper().createObjectNode();
-        for (String key : annotations.keys()) {
+        Set<String> keys = new TreeSet<>(annotations.keys());
+        for (String key : keys) {
             result.put(key, annotations.value(key));
         }
         return result;