lib/json: there's no need for the length attribute in the generated JSON
authorAlexis Laferrière <alexis.laf@xymus.net>
Mon, 29 Jun 2015 10:44:37 +0000 (06:44 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Mon, 29 Jun 2015 11:25:21 +0000 (07:25 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/json/serialization.nit
tests/sav/test_json_deserialization_alt1.res

index f7c161e..db9b626 100644 (file)
@@ -411,9 +411,7 @@ redef class SimpleCollection[E]
                        v.stream.write id.to_s
                        v.stream.write """, "__class": """"
                        v.stream.write class_name
-                       v.stream.write """", "__length": """
-                       v.stream.write length.to_s
-                       v.stream.write """, "__items": """
+                       v.stream.write """", "__items": """
                end
 
                serialize_to_pure_json v
@@ -430,10 +428,9 @@ redef class SimpleCollection[E]
                        v.notify_of_creation self
                        init
 
-                       var length = v.deserialize_attribute("__length").as(Int)
                        var arr = v.path.last["__items"].as(SequenceRead[nullable Object])
-                       for i in length.times do
-                               var obj = v.convert_object(arr[i])
+                       for o in arr do
+                               var obj = v.convert_object(o)
                                self.add obj
                        end
                end
index 8c7e49a..36fed28 100644 (file)
@@ -40,7 +40,7 @@
 <E: a: hello, 1234, 123.4; b: hella, 2345, 234.5>
 
 # Json:
-{"__kind": "obj", "__id": 0, "__class": "E", "a": {"__kind": "obj", "__id": 1, "__class": "Array[Object]", "__length": 3, "__items": ["hello", 1234, 123.4]}, "b": ["hella", 2345, 234.5]}
+{"__kind": "obj", "__id": 0, "__class": "E", "a": {"__kind": "obj", "__id": 1, "__class": "Array[Object]", "__items": ["hello", 1234, 123.4]}, "b": ["hella", 2345, 234.5]}
 
 # Back in Nit:
 <E: a: hello, 1234, 123.4; b: hella, 2345, 234.5>
@@ -67,7 +67,7 @@
 <G: hs: -1, 0; s: one, two; hm: one. 1, two. 2; am: three. 3, four. 4>
 
 # Json:
-{"__kind": "obj", "__id": 0, "__class": "G", "hs": {"__kind": "obj", "__id": 1, "__class": "HashSet[Int]", "__length": 2, "__items": [-1, 0]}, "s": {"__kind": "obj", "__id": 2, "__class": "ArraySet[String]", "__length": 2, "__items": ["one", "two"]}, "hm": {"__kind": "obj", "__id": 3, "__class": "HashMap[String, Int]", "__length": 2, "__keys": ["one", "two"], "__values": [1, 2]}, "am": {"__kind": "obj", "__id": 4, "__class": "ArrayMap[String, String]", "__length": 2, "__keys": ["three", "four"], "__values": ["3", "4"]}}
+{"__kind": "obj", "__id": 0, "__class": "G", "hs": {"__kind": "obj", "__id": 1, "__class": "HashSet[Int]", "__items": [-1, 0]}, "s": {"__kind": "obj", "__id": 2, "__class": "ArraySet[String]", "__items": ["one", "two"]}, "hm": {"__kind": "obj", "__id": 3, "__class": "HashMap[String, Int]", "__length": 2, "__keys": ["one", "two"], "__values": [1, 2]}, "am": {"__kind": "obj", "__id": 4, "__class": "ArrayMap[String, String]", "__length": 2, "__keys": ["three", "four"], "__values": ["3", "4"]}}
 
 # Back in Nit:
 <G: hs: -1, 0; s: one, two; hm: one. 1, two. 2; am: three. 3, four. 4>