serialization :: SafeDeserializer :: accept
Shouldself
accept to deserialize an instance of dynamic_type
for an attribute wuth static_type
?
serialization :: SafeDeserializer :: check_subtypes
Should objects be checked if they a subtype of the static type before deserialization?serialization :: SafeDeserializer :: check_subtypes=
Should objects be checked if they a subtype of the static type before deserialization?serialization :: SafeDeserializer :: whitelist
Accepted parameterized classes to deserializeserialization :: SafeDeserializer :: whitelist=
Accepted parameterized classes to deserializeserialization $ SafeDeserializer :: SELF
Type of this instance, automatically specialized in every classserialization :: SafeDeserializer :: accept
Shouldself
accept to deserialize an instance of dynamic_type
for an attribute wuth static_type
?
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
serialization :: SafeDeserializer :: check_subtypes
Should objects be checked if they a subtype of the static type before deserialization?serialization :: SafeDeserializer :: check_subtypes=
Should objects be checked if they a subtype of the static type before deserialization?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 :: Deserializer :: deserialize
Deserialize and return an object, storing errors in the attributeerrors
serialization :: Deserializer :: deserialize_attribute
Deserialize the attribute withname
from the object open for deserialization
serialization :: Deserializer :: deserialize_attribute_missing
Was the attribute queried by the last call todeserialize_attribute
missing?
serialization :: Deserializer :: deserialize_attribute_missing=
Was the attribute queried by the last call todeserialize_attribute
missing?
serialization :: Deserializer :: deserialize_class
Deserialize the next available object as an instance ofclass_name
serialization :: Deserializer :: deserialize_class_intern
Generated service to deserialize the next available object as an instance ofclass_name
serialization :: Deserializer :: errors
Errors encountered in the last call todeserialize
serialization :: Deserializer :: errors=
Errors encountered in the last call todeserialize
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 :: Deserializer :: keep_going
Shouldself
keep trying to deserialize an object after an error?
serialization :: Deserializer :: keep_going=
Shouldself
keep trying to deserialize an object after an error?
serialization :: Serializable :: msgpack_extra_array_items
Hook to request a larger than usual metadata arrayserialization :: Deserializer :: notify_of_creation
Register a newly allocated object (even if not completely built)core :: Object :: output_class_name
Display class name on stdout (debug only).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
serialization :: SafeDeserializer :: whitelist
Accepted parameterized classes to deserializeserialization :: SafeDeserializer :: whitelist=
Accepted parameterized classes to deserializeSerializer::serialize
msgpack :: MsgPackDeserializer
Deserialize MessagePack format to full Nit objects
# Deserialization engine limiting which types can be deserialized
class SafeDeserializer
super Deserializer
# Accepted parameterized classes to deserialize
#
# If `whitelist.empty`, all types are accepted.
#
# ~~~
# import json
#
# class MyClass
# serialize
# end
#
# var json_string = """
# {"__class": "MyClass"}
# """
#
# var deserializer = new JsonDeserializer(json_string)
# var obj = deserializer.deserialize
# assert deserializer.errors.is_empty
# assert obj isa MyClass
#
# deserializer = new JsonDeserializer(json_string)
# deserializer.whitelist.add "Array[String]"
# deserializer.whitelist.add "AnotherAcceptedClass"
# obj = deserializer.deserialize
# assert deserializer.errors.length == 1
# assert obj == null
# ~~~
var whitelist = new Array[Text]
# Should objects be checked if they a subtype of the static type before deserialization?
#
# Defaults to `true`, as it should always be activated.
# It can be turned off to implement the subtype check itself.
var check_subtypes = true is writable
# Should `self` accept to deserialize an instance of `dynamic_type` for an attribute wuth `static_type`?
#
# Uses `whitelist` if not empty...
# Check correct inheritance if `check_subtypes`...
fun accept(dynamic_type: Text, static_type: nullable Text): Bool
do
if whitelist.not_empty and not whitelist.has(dynamic_type) then
errors.add new Error("Deserialization Error: '{dynamic_type}' not in whitelist")
return false
end
if static_type != null and check_subtypes then
var static_class = static_type.strip_nullable_and_params.to_s
var dynamic_class = dynamic_type.strip_nullable_and_params.to_s
if not class_inheritance_metamodel.has_edge(dynamic_class, static_class) then
errors.add new Error("Deserialization Error: `{dynamic_type}` is not a subtype of the static type `{static_type}`")
return false
end
end
return true
end
end
lib/serialization/safe.nit:23,1--84,3