lib/serialization: fix deserialization contructor calling the default init
[nit.git] / lib / serialization / serialization.nit
index d120254..7c689b6 100644 (file)
@@ -106,9 +106,18 @@ abstract class Deserializer
        # This method should be redefined for each custom subclass of `Serializable`.
        # All refinement should look for a precise `class_name` and call super
        # on unsupported classes.
-       fun deserialize_class(class_name: String): Object do
-               print "Error: doesn't know how to deserialize class \"{class_name}\""
-               abort
+       protected fun deserialize_class(class_name: String): nullable Object do
+               return deserialize_class_intern(class_name)
+       end
+
+       # Generated service to deserialize the next available object as an instance of `class_name`
+       #
+       # Refinements to this method will be generated by the serialization phase.
+       # To avoid conflicts, there should not be any other refinements to this method.
+       # You can instead use `deserialize_class`.
+       protected fun deserialize_class_intern(class_name: String): nullable Object do
+               errors.add new Error("Deserialization Error: Doesn't know how to deserialize class \"{class_name}\"")
+               return null
        end
 
        # Should `self` keep trying to deserialize an object after an error?
@@ -122,7 +131,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]
@@ -182,7 +191,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
@@ -233,7 +242,7 @@ redef class Couple[F, S]
        end
 end
 
-redef class Container[E]
+redef class Ref[E]
        super Serializable
 
        redef init from_deserializer(v)