# Abstract deserialization service
#
# The main service is `deserialize`.
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(static_type: nullable String): nullable Object is abstract
# Deserialize the attribute with `name` from the object open for deserialization
#
# The `static_type` restricts what kind of object can be deserialized.
#
# Return the deserialized value or null on error, and set
# `deserialize_attribute_missing` to whether the attribute was missing.
#
# Internal method to be implemented by the engines.
fun deserialize_attribute(name: String, static_type: nullable String): nullable Object is abstract
# Was the attribute queried by the last call to `deserialize_attribute` missing?
var deserialize_attribute_missing = false
# Register a newly allocated object (even if not completely built)
#
# Internal method called by objects in creation, to be implemented by the engines.
fun notify_of_creation(new_object: Object) is abstract
# Deserialize the next available object as an instance of `class_name`
#
# Return the deserialized object on success and
# record in `errors` if `class_name` is unknown.
#
# 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.
protected fun deserialize_class(class_name: Text): nullable Object do
if class_name == "Error" then return new Error.from_deserializer(self)
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: Text): 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?
#
# This behavior takes effect after each attribute deserialization with
# errors such as a missing attribute or the value is of the wrong type.
# If `keep_going`, the attribute will be skipped but the engine will
# deserialize the next attribute.
# If `not keep_going`, the engine stops deserializing right away.
#
# When at `true`, this may cause the accumulation of a lot of entries in `errors`.
#
# Default at `true`.
var keep_going: nullable Bool = null is writable
# Errors encountered in the last call to `deserialize`
var errors = new Array[Error]
end
lib/serialization/serialization_core.nit:107,1--174,3