From: Alexis Laferrière Date: Sat, 10 Sep 2016 20:41:06 +0000 (-0400) Subject: lib serialization: `deserialize` accepts the name of the static type as argument X-Git-Url: http://nitlanguage.org lib serialization: `deserialize` accepts the name of the static type as argument Signed-off-by: Alexis Laferrière --- diff --git a/lib/binary/serialization.nit b/lib/binary/serialization.nit index f4228b3..580639e 100644 --- a/lib/binary/serialization.nit +++ b/lib/binary/serialization.nit @@ -304,7 +304,7 @@ class BinaryDeserializer return null end - redef fun deserialize + redef fun deserialize(static_type) do errors.clear diff --git a/lib/json/serialization_read.nit b/lib/json/serialization_read.nit index 91959c1..91bd914 100644 --- a/lib/json/serialization_read.nit +++ b/lib/json/serialization_read.nit @@ -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` diff --git a/lib/serialization/serialization.nit b/lib/serialization/serialization.nit index db02122..b39c1aa 100644 --- a/lib/serialization/serialization.nit +++ b/lib/serialization/serialization.nit @@ -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 #