From: Alexis Laferrière Date: Mon, 29 Jun 2015 10:44:37 +0000 (-0400) Subject: lib/json: there's no need for the length attribute in the generated JSON X-Git-Tag: v0.7.6~4^2~10 X-Git-Url: http://nitlanguage.org lib/json: there's no need for the length attribute in the generated JSON Signed-off-by: Alexis Laferrière --- diff --git a/lib/json/serialization.nit b/lib/json/serialization.nit index f7c161e..db9b626 100644 --- a/lib/json/serialization.nit +++ b/lib/json/serialization.nit @@ -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 diff --git a/tests/sav/test_json_deserialization_alt1.res b/tests/sav/test_json_deserialization_alt1.res index 8c7e49a..36fed28 100644 --- a/tests/sav/test_json_deserialization_alt1.res +++ b/tests/sav/test_json_deserialization_alt1.res @@ -40,7 +40,7 @@ # 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: @@ -67,7 +67,7 @@ # 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: