json: deser. chars serialized as strings and bytes as ints
authorAlexis Laferrière <alexis.laf@xymus.net>
Thu, 27 Jul 2017 16:05:13 +0000 (12:05 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Thu, 10 Aug 2017 16:19:29 +0000 (12:19 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/json/serialization_read.nit

index 3c8b170..13a48d1 100644 (file)
@@ -326,6 +326,16 @@ class JsonDeserializer
                        return array
                end
 
+               if object isa String and object.length == 1 and static_type == "Char" then
+                       # Char serialized as a JSON string
+                       return object.chars.first
+               end
+
+               if object isa Int and static_type == "Byte" then
+                       # Byte serialized as an integer
+                       return object.to_b
+               end
+
                return object
        end