serialization :: E
This factorizes most services and domain knowledge used by the RestrictedSerializer
In real enterprise-level code, the various specific behaviors can be specified in more semantic classifiers.
serialization :: E :: defaultinit
serialization :: E :: phantom
A phantom attribute to be serialized by the customRestrictedSerializer
.
serialization :: E :: semi_private
An attribute not to be serialized by the customRestrictedSerializer
.
serialization :: E :: semi_private=
An attribute not to be serialized by the customRestrictedSerializer
.
serialization :: E :: ser_json
Test method that serializesself
and prints with the standard JsonSerializer
serialization :: E :: ser_json2
Test method that serializesself
and prints with the custom RestrictedJsonSerializer.
serialization $ E :: SELF
Type of this instance, automatically specialized in every classserialization $ E :: core_serialize_to
Actual serialization ofself
to serializer
serialization $ E :: from_deserializer
Create an instance of this class from thedeserializer
serialization :: Serializable :: accept_json_serializer
Refinable service to customize the serialization of this class to JSONserialization :: Serializable :: accept_msgpack_attribute_counter
Hook to customize the behavior of theAttributeCounter
serialization :: Serializable :: accept_msgpack_serializer
Hook to customize the serialization of this class to MessagePackserialization :: Serializable :: add_to_bundle
Called by[]=
to dynamically choose the appropriate method according
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
serialization :: Serializable :: core_serialize_to
Actual serialization ofself
to serializer
core :: Object :: defaultinit
serialization :: E :: defaultinit
serialization :: Serializable :: from_deserializer
Create an instance of this class from thedeserializer
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
serialization :: Serializable :: msgpack_extra_array_items
Hook to request a larger than usual metadata arraycore :: Object :: output_class_name
Display class name on stdout (debug only).serialization :: E :: phantom
A phantom attribute to be serialized by the customRestrictedSerializer
.
serialization :: E :: semi_private
An attribute not to be serialized by the customRestrictedSerializer
.
serialization :: E :: semi_private=
An attribute not to be serialized by the customRestrictedSerializer
.
serialization :: E :: ser_json
Test method that serializesself
and prints with the standard JsonSerializer
serialization :: E :: ser_json2
Test method that serializesself
and prints with the custom RestrictedJsonSerializer.
serialization :: Serializable :: serialize_msgpack
Serializeself
to MessagePack bytes
serialization :: Serializable :: serialize_to
Serializeself
to serializer
serialization :: Serializable :: serialize_to_json
Serializeself
to JSON
serialization :: Serializable :: to_pretty_json
Serializeself
to plain pretty JSON
Serializer::serialize
# The root class of the business objects.
# This factorizes most services and domain knowledge used by the `RestrictedSerializer`
#
# In real enterprise-level code, the various specific behaviors can be specified in more semantic classifiers.
abstract class E
serialize
# The semantic business identifier.
#
# With the `RestrictedSerializer`, references to `E` objects will be replaced with `id`-based information.
# This avoid to duplicate or enlarge the information cross-call wise.
#
# A future API/REST call can then request the _missing_ object from its identifier.
var id: String
# A phantom attribute to be serialized by the custom `RestrictedSerializer`.
#
# This can be used to inject constant or computed information that make little sense to have as a genuine attribute in
# the Nit model.
fun phantom: String do return "So Much Fun"
# An attribute not to be serialized by the custom `RestrictedSerializer`.
# e.g. we want it on the DB but not in API/REST JSON messages
#
# Note that the annotation `noserialize` hides the attribute for all serializers.
# To hide the attribute only in the `RestrictedSerializer`, it will have to actively ignore it.
var semi_private = "secret"
# Test method that serializes `self` and prints with the standard JsonSerializer
fun ser_json
do
var w = new StringWriter
var js = new JsonSerializer(w)
js.plain_json = true
js.serialize(self)
print w
end
# Test method that serializes `self` and prints with the custom RestrictedJsonSerializer.
fun ser_json2
do
var w = new StringWriter
var js = new RestrictedJsonSerializer(w)
js.plain_json = true
js.serialize(self)
print w
end
end
lib/serialization/examples/custom_serialization.nit:37,1--84,3