deserializer
This constructor is refined by subclasses to correctly build their instances.
# Create an instance of this class from the `deserializer`
#
# This constructor is refined by subclasses to correctly build their instances.
init from_deserializer(deserializer: Deserializer) is nosuper do end
lib/serialization/serialization_core.nit:244,2--247,69
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(deserializer)
do
deserializer.notify_of_creation self
var nodes = deserializer.deserialize_attribute("nodes", (new GetName[Set[N]]).to_s)
if deserializer.deserialize_attribute_missing then
deserializer.errors.add new AttributeMissingError(self, "nodes")
end
if nodes isa Set[N] then self.nodes = nodes
var links = deserializer.deserialize_attribute("links", (new GetName[Set[L]]).to_s)
if deserializer.deserialize_attribute_missing then
deserializer.errors.add new AttributeMissingError(self, "links")
end
if links isa Set[L] then for link in links do add_link link
end
lib/a_star/a_star.nit:282,2--297,4
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v)
do
v.notify_of_creation self
var message = v.deserialize_attribute("message")
if not message isa String then message = ""
init message
var cause = v.deserialize_attribute("cause")
if cause isa nullable Error then self.cause = cause
end
lib/serialization/serialization_core.nit:305,2--315,4
redef init from_deserializer(v)
do
v.notify_of_creation self
var first = v.deserialize_attribute("first")
var second = v.deserialize_attribute("second")
init(first, second)
end
lib/serialization/serialization_core.nit:271,2--277,4
redef init from_deserializer(v)
do
# Code generated by the serialization_phase from the compiler frontend,
# copied here for compatibility with nith.
super
v.notify_of_creation self
var poset = v.deserialize_attribute("poset", "POSet[nullable Object]")
if v.deserialize_attribute_missing then
v.errors.add new Error("Deserialization Error: attribute `{class_name}::poset` missing from JSON object")
else if not poset isa POSet[E] then
v.errors.add new AttributeTypeError(self, "poset", poset, "POSet[nullable Object]")
if v.keep_going == false then return
else
self.poset = poset
end
var element = v.deserialize_attribute("element", "nullable Object")
if v.deserialize_attribute_missing then
v.errors.add new Error("Deserialization Error: attribute `{class_name}::element` missing from JSON object")
else if not element isa E then
v.errors.add new AttributeTypeError(self, "element", element, "nullable Object")
if v.keep_going == false then return
else
self.element = element
end
var tos = v.deserialize_attribute("tos", "HashSet[nullable Object]")
if v.deserialize_attribute_missing then
else if not tos isa HashSet[E] then
v.errors.add new AttributeTypeError(self, "tos", tos, "HashSet[nullable Object]")
if v.keep_going == false then return
else
self.tos = tos
end
var froms = v.deserialize_attribute("froms", "HashSet[nullable Object]")
if v.deserialize_attribute_missing then
else if not froms isa HashSet[E] then
v.errors.add new AttributeTypeError(self, "froms", froms, "HashSet[nullable Object]")
if v.keep_going == false then return
else
self.froms = froms
end
var dtos = v.deserialize_attribute("dtos", "HashSet[nullable Object]")
if v.deserialize_attribute_missing then
else if not dtos isa HashSet[E] then
v.errors.add new AttributeTypeError(self, "dtos", dtos, "HashSet[nullable Object]")
if v.keep_going == false then return
else
self.dtos = dtos
end
var dfroms = v.deserialize_attribute("dfroms", "HashSet[nullable Object]")
if v.deserialize_attribute_missing then
else if not dfroms isa HashSet[E] then
v.errors.add new AttributeTypeError(self, "dfroms", dfroms, "HashSet[nullable Object]")
if v.keep_going == false then return
else
self.dfroms = dfroms
end
var count = v.deserialize_attribute("count", "Int")
if v.deserialize_attribute_missing then
v.errors.add new Error("Deserialization Error: attribute `{class_name}::count` missing from JSON object")
else if not count isa Int then
v.errors.add new AttributeTypeError(self, "count", count, "Int")
if v.keep_going == false then return
else
self.count = count
end
end
lib/poset/poset.nit:657,2--730,4
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v)
do
super
if v isa JsonDeserializer then
v.notify_of_creation self
init
var keys_type_name = (new GetName[K]).to_s
var values_type_name = (new GetName[V]).to_s
var length = v.deserialize_attribute("__length")
var keys = v.path.last.get_or_null("__keys")
var values = v.path.last.get_or_null("__values")
if keys == null and values == null then
# Fallback to a plain object
for key, value_src in v.path.last do
var value = v.convert_object(value_src, values_type_name)
if not key isa K then
v.errors.add new AttributeTypeError(self, "keys", key, keys_type_name)
continue
end
if not value isa V then
v.errors.add new AttributeTypeError(self, "values", value, values_type_name)
continue
end
self[key] = value
end
return
end
# Length is optional
if length == null and keys isa SequenceRead[nullable Object] then length = keys.length
# Consistency check
if not length isa Int or length < 0 or
not keys isa SequenceRead[nullable Object] or
not values isa SequenceRead[nullable Object] or
keys.length != values.length or length != keys.length then
# If there is nothing or length == 0, we consider that it is an empty Map.
if (length != null and length != 0) or keys != null or values != null then
v.errors.add new Error("Deserialization Error: invalid format in {self.class_name}")
end
return
end
# First, convert all keys to follow the order of the serialization
var converted_keys = new Array[K]
for i in length.times do
var key = v.convert_object(keys[i], keys_type_name)
if not key isa K then
v.errors.add new AttributeTypeError(self, "keys", key, keys_type_name)
continue
end
converted_keys.add key
end
# Then convert the values and build the map
for i in length.times do
var key = converted_keys[i]
var value = v.convert_object(values[i], values_type_name)
if not value isa V then
v.errors.add new AttributeTypeError(self, "values", value, values_type_name)
continue
end
if has_key(key) then
v.errors.add new Error("Deserialization Error: duplicated key '{key or else "null"}' in {self.class_name}, previous value overwritten")
end
self[key] = value
end
end
end
lib/json/serialization_read.nit:420,2--502,4
redef init from_deserializer(v)
do
super
if v isa MsgPackDeserializer then
v.notify_of_creation self
init
var open_object = v.path_arrays.last
var msgpack_items
if open_object != null then
# Metadata available
msgpack_items = open_object.last
else
msgpack_items = v.path.last
end
if not msgpack_items isa Map[nullable Object, nullable Object] then
v.errors.add new Error("Deserialization Error: no key/values in source of `{class_name}`")
return
end
var keys_type_name = (new GetName[K]).to_s
var values_type_name = (new GetName[V]).to_s
for key_src, value_src in msgpack_items do
var key = v.convert_object(key_src, keys_type_name)
if not key isa K then
v.errors.add new AttributeTypeError(self, "keys", key, keys_type_name)
continue
end
var value = v.convert_object(value_src, values_type_name)
if not value isa V then
v.errors.add new AttributeTypeError(self, "values", value, values_type_name)
continue
end
self[key] = value
end
end
end
lib/msgpack/serialization_read.nit:368,2--409,4
redef init from_deserializer(v)
do
v.notify_of_creation self
var item = v.deserialize_attribute("item")
init item
end
lib/serialization/serialization_core.nit:289,2--294,4
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v)
do
super
if v isa JsonDeserializer then
v.notify_of_creation self
init
var open_array: nullable SequenceRead[nullable Object] = v.opened_array
if open_array == null then
# With metadata
var arr = v.path.last.get_or_null("__items")
if not arr isa SequenceRead[nullable Object] then
# If there is nothing, we consider that it is an empty collection.
if arr != null then v.errors.add new Error("Deserialization Error: invalid format in {self.class_name}")
return
end
open_array = arr
end
# Name of the dynamic name of E
var items_type_name = (new GetName[E]).to_s
# Fill array
for o in open_array do
var obj = v.convert_object(o, items_type_name)
if obj isa E then
add obj
else v.errors.add new AttributeTypeError(self, "items", obj, items_type_name)
end
end
end
lib/json/serialization_read.nit:386,2--416,4
redef init from_deserializer(v)
do
super
if v isa MsgPackDeserializer then
v.notify_of_creation self
init
var open_array = v.path_arrays.last
var msgpack_items = null
if open_array != null then msgpack_items = open_array.last
if not msgpack_items isa Array[nullable Serializable] then
v.errors.add new Error("Deserialization Error: no items in source of `{class_name}`")
return
end
# Name of the dynamic name of E
var items_type_name = (new GetName[E]).to_s
# Fill array
for o in msgpack_items do
var obj = v.convert_object(o, items_type_name)
if obj isa E then
add obj
else v.errors.add new AttributeTypeError(self, "items", obj, items_type_name)
end
end
end
lib/msgpack/serialization_read.nit:337,2--364,4
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(deserializer)
do
deserializer.notify_of_creation self
var elements = deserializer.deserialize_attribute("elements")
if elements isa HashMap[E, POSetElement[E]] then
self.elements = elements
end
end
lib/poset/poset.nit:499,2--506,4
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v)
do
v.notify_of_creation self
var seq = v.deserialize_attribute("seq", (new GetName[Sequence[E]]).to_s)
if not seq isa Sequence[E] then seq = new Array[E]
if v.deserialize_attribute_missing then
v.errors.add new AttributeMissingError(self, "seq")
end
init seq
end
lib/serialization/serialization_core.nit:329,2--340,4
redef init from_deserializer(v)
do
v.notify_of_creation self
var seq = v.deserialize_attribute("seq", (new GetName[SimpleCollection[E]]).to_s)
if not seq isa SimpleCollection[E] then seq = new Array[E]
if v.deserialize_attribute_missing then
v.errors.add new AttributeMissingError(self, "seq")
end
init seq
end
lib/serialization/serialization_core.nit:347,2--358,4
redef init from_deserializer(v)
do
v.notify_of_creation self
var items = v.deserialize_attribute("items", (new GetName[SimpleCollection[E]]).to_s)
if not items isa Array[E] then items = new Array[E]
if v.deserialize_attribute_missing then
v.errors.add new AttributeMissingError(self, "items")
end
var comparator = v.deserialize_attribute("comparator", "Comparator")
if not comparator isa Comparator then comparator = default_comparator
if v.deserialize_attribute_missing then
v.errors.add new AttributeMissingError(self, "comparator")
end
init comparator
self.items.add_all items
end
lib/serialization/serialization_core.nit:365,2--383,4
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40
redef init from_deserializer(v) do abort
2,1--40