From: Jean Privat Date: Sat, 23 May 2015 01:01:11 +0000 (-0400) Subject: Merge: Nit objects to plain JSON X-Git-Tag: v0.7.5~38 X-Git-Url: http://nitlanguage.org Merge: Nit objects to plain JSON Adds an option to write Nit objects to plain JSON in `JsonSerializer`, and the shortcut `Serializable::to_plain_json`. This format lacks the meta-data necessary for the full deserialization but it is easier to read for non-Nit programs and humans. You can see an example in the doc of `json::serialization` and here, taken from the tests. The following class uses "complex" Nit data structures and serialize them to the closest available structure in JSON. ~~~nit class G auto_serializable var hs = new HashSet[Int] var s = new ArraySet[String] var hm = new HashMap[String, Int] var am = new ArrayMap[String, String] init do hs.add -1 hs.add 0 s.add "one" s.add "two" hm["one"] = 1 hm["two"] = 2 am["three"] = "3" am["four"] = "4" end end var g = new G g.to_plain_json # ... ~~~ ~~~json {"hs": [-1, 0], "s": ["one", "two"], "hm": {"one": 1, "two": 2}, "am": {"three": "3", "four": "4"}} ~~~ Of course, when writing to a file or in a socket, it is better to use `JsonSerializer` as the `to_plain_json` version uses a string. Pull-Request: #1360 Reviewed-by: Lucas Bajolet Reviewed-by: Alexandre Terrasa --- a05897f89603d0dc2880aa287b966bb6e0f4a39f