lib serialization: `deserialize` accepts the name of the static type as argument
authorAlexis Laferrière <alexis.laf@xymus.net>
Sat, 10 Sep 2016 20:41:06 +0000 (16:41 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Fri, 14 Oct 2016 23:55:48 +0000 (19:55 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/binary/serialization.nit
lib/json/serialization_read.nit
lib/serialization/serialization.nit

index f4228b3..580639e 100644 (file)
@@ -304,7 +304,7 @@ class BinaryDeserializer
                return null
        end
 
-       redef fun deserialize
+       redef fun deserialize(static_type)
        do
                errors.clear
 
index 91959c1..91bd914 100644 (file)
@@ -321,10 +321,10 @@ class JsonDeserializer
        # Current array open for deserialization, used by `SimpleCollection::from_deserializer`
        private var opened_array: nullable Array[nullable Object] = null
 
-       redef fun deserialize
+       redef fun deserialize(static_type)
        do
                errors.clear
-               return convert_object(root)
+               return convert_object(root, static_type)
        end
 
        # User customizable heuristic to infer the name of the Nit class to deserialize `json_object`
index db02122..b39c1aa 100644 (file)
@@ -92,8 +92,10 @@ end
 abstract class Deserializer
        # Deserialize and return an object, storing errors in the attribute `errors`
        #
+       # If a `static_type` is given, only subtypes of the `static_type` are accepted.
+       #
        # This method behavior varies according to the implementation engines.
-       fun deserialize: nullable Object is abstract
+       fun deserialize(static_type: nullable String): nullable Object is abstract
 
        # Deserialize the attribute with `name` from the object open for deserialization
        #