Merge pull request #2424 from alexrp/task-unobserved-exceptions
[mono.git] / mcs / class / System.Json / System.Json / JsonObject.cs
index 487b29694ebd3717efb2123c857252a83d344b21..91366a2243a766eac337d7bc7739dfa3df5035be 100644 (file)
@@ -12,11 +12,12 @@ namespace System.Json
 {
        public class JsonObject : JsonValue, IDictionary<string, JsonValue>, ICollection<JsonPair>
        {
-               Dictionary<string, JsonValue> map;
+               // Use SortedDictionary to make result of ToString() deterministic
+               SortedDictionary<string, JsonValue> map;
 
                public JsonObject (params JsonPair [] items)
                {
-                       map = new Dictionary<string, JsonValue> ();
+                       map = new SortedDictionary<string, JsonValue> (StringComparer.Ordinal);
 
                        if (items != null)
                                AddRange (items);
@@ -27,7 +28,7 @@ namespace System.Json
                        if (items == null)
                                throw new ArgumentNullException ("items");
 
-                       map = new Dictionary<string, JsonValue> ();
+                       map = new SortedDictionary<string, JsonValue> (StringComparer.Ordinal);
                        AddRange (items);
                }
 
@@ -141,7 +142,13 @@ namespace System.Json
                                stream.WriteByte ((byte) '"');
                                stream.WriteByte ((byte) ',');
                                stream.WriteByte ((byte) ' ');
-                               pair.Value.Save (stream);
+                               if (pair.Value == null) {
+                                       stream.WriteByte ((byte) 'n');
+                                       stream.WriteByte ((byte) 'u');
+                                       stream.WriteByte ((byte) 'l');
+                                       stream.WriteByte ((byte) 'l');
+                               } else
+                                       pair.Value.Save (stream);
                        }
                        stream.WriteByte ((byte) '}');
                }