Property definitions

serialization $ Serializer :: defaultinit
# Abstract serialization service to be sub-classed by specialized services.
interface Serializer
	# Entry point method of this service, serialize the `object`
	#
	# This method, and refinements, should handle `null` and probably
	# use double dispatch to customize the bahavior per serializable objects.
	fun serialize(object: nullable Serializable) is abstract

	# The object currently serialized by `serialized`
	#
	# Can be used by a custom serializer to add domain-specific serialization behavior.
	protected fun current_object: nullable Object is abstract

	# Serialize an object, with full serialization or a simple reference
	protected fun serialize_reference(object: Serializable) is abstract

	# Serialize an attribute to compose a serializable object
	#
	# This method should be called from `Serializable::core_serialize_to`.
	fun serialize_attribute(name: String, value: nullable Object)
	do
		if not try_to_serialize(value) then
			assert value != null # null would have been serialized
			warn("argument {name} of type {value.class_name} is not serializable.")
		end
	end

	# Serialize `value` is possible, i.e. it is `Serializable` or `null`
	fun try_to_serialize(value: nullable Object): Bool
	do
		if value isa Serializable then
			value.serialize_to_or_delay(self)
		else if value == null then
			serialize value
		else return false
		return true
	end

	# The method is called when a standard `value` is serialized
	#
	# The default behavior is to call `value.core_serialize_to(self)` but it
	# can be redefined by a custom serializer to add domain-specific serialization behavior.
	fun serialize_core(value: Serializable)
	do
		value.core_serialize_to(self)
	end

	# Warn of problems and potential errors (such as if an attribute
	# is not serializable)
	fun warn(msg: String) do print "Serialization warning: {msg}"
end
lib/serialization/serialization_core.nit:55,1--105,3