lib/glesv2: intro glGetProgramiv and glGetShaderiv, and clean related services
[nit.git] / lib / serialization / serialization.nit
index 1fec7e9..10caaef 100644 (file)
@@ -107,6 +107,7 @@ abstract class Deserializer
        # All refinement should look for a precise `class_name` and call super
        # on unsupported classes.
        protected fun deserialize_class(class_name: String): nullable Object do
+               if class_name == "Error" then return new Error.from_deserializer(self)
                return deserialize_class_intern(class_name)
        end
 
@@ -131,7 +132,7 @@ abstract class Deserializer
        # When at `true`, this may cause the accumulation of a lot of entries in `errors`.
        #
        # Default at `true`.
-       var keep_going: nullable Bool is writable
+       var keep_going: nullable Bool = null is writable
 
        # Errors encountered in the last call to `deserialize`
        var errors = new Array[Error]
@@ -191,7 +192,7 @@ interface Serializable
        # Create an instance of this class from the `deserializer`
        #
        # This constructor is refined by subclasses to correctly build their instances.
-       init from_deserializer(deserializer: Deserializer) do end
+       init from_deserializer(deserializer: Deserializer) is nosuper do end
 end
 
 redef interface Object
@@ -257,3 +258,25 @@ redef class Ref[E]
                v.serialize_attribute("item", first)
        end
 end
+
+redef class Error
+       super Serializable
+
+       redef init from_deserializer(v)
+       do
+               v.notify_of_creation self
+
+               var message = v.deserialize_attribute("message")
+               if not message isa String then message = ""
+               init message
+
+               var cause = v.deserialize_attribute("cause")
+               if cause isa nullable Error then self.cause = cause
+       end
+
+       redef fun core_serialize_to(v)
+       do
+               v.serialize_attribute("message", message)
+               v.serialize_attribute("cause", cause)
+       end
+end