This method should be called from Serializable::core_serialize_to
.
# 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
lib/serialization/serialization_core.nit:71,2--80,4
redef fun serialize_attribute(name, object) do count += 1
lib/msgpack/serialization_write.nit:158,2--58
# This method is called when trying to serialize a specific attribute
redef fun serialize_attribute(name, value)
do
var recv = current_object
if recv isa E then
# do not serialize `E::semi_private`
if name == "semi_private" then return
end
if value isa E then
# Do not serialize references to `E`.
# Just use a domain-specific value that make sense in the business logic.
serialize_attribute(name, "ID:" + value.id)
return
end
super
end
lib/serialization/examples/custom_serialization.nit:104,2--121,4
redef fun serialize_attribute(name, value)
do
if not plain_json or not first_attribute then
stream.write ","
end
first_attribute = false
new_line_and_indent
stream.write "\""
stream.write name
stream.write "\":"
if pretty_json then stream.write " "
super
end
lib/json/serialization_write.nit:103,2--116,4
redef fun serialize_attribute(name, value)
do
serialize_meta_string name
super
end
lib/msgpack/serialization_write.nit:111,2--115,4