module json_serialization
import serialization
-import simple_json_reader
+import json::static
class JsonSerializer
super Serializer
var just_opened_id: nullable Int = null
- init(text: String)
+ init(text: Text)
do
var root = text.json_to_nit_object
if root isa HashMap[String, nullable Object] then path.add(root)
return value
end
- # char? TODO
+ # char?
+ if kind == "char" then
+ assert object.keys.has("__val")
+ var val = object["__val"]
+ assert val isa String
- print "Malformed Json string: unexpected Json Object kind '{kind}'"
+ if val.length != 1 then print "Error: expected a single char when deserializing '{val}'."
+
+ return val.chars.first
+ end
+
+ print "Malformed Json string: unexpected Json Object kind '{kind or else "null"}'"
abort
end
end
redef class Char
- redef fun serialize_to_json(v) do v.stream.write("'{to_s}'")
+ redef fun serialize_to_json(v) do v.stream.write "\{\"__kind\": \"char\", \"__val\": \"{to_s.to_json_s}\"\}"
end
redef class String