Serializer::serialize
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 :: Serializable :: core_serialize_to
Actual serialization ofself
to serializer
serialization :: Serializable :: from_deserializer
Create an instance of this class from thedeserializer
serialization :: Serializable :: msgpack_extra_array_items
Hook to request a larger than usual metadata arrayserialization :: 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 $ Serializable :: SELF
Type of this instance, automatically specialized in every classserialization :: inspect $ Serializable :: inspect
Improve the default inspection reading serializable attributesserialization :: 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 :: 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 :: 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
more_collections :: BestDistance
Keep track of the best elements according to a distance value.serialization :: DirectSerializable
Instances of this class are not delayed and instead serialized immediatelyHttpRequestParser
json :: JsonMapRead
A map that can be translated into a JSON object.github :: RepoEntity
serialization :: AttributeError
Deserialization error related to an attribute ofreceiver
dot :: AttributeMap
Map of graph/node/edge attribute that can be rendered to dot.serialization :: AttributeMissingError
Missing attribute at deserializationserialization :: AttributeTypeError
Invalid dynamic type for a deserialized attributeConcurrentList
Array
List
pthreads :: ConcurrentSequence
A concurrent variant to the standardSequence
more_collections :: DefaultMap
A map with a default value.github :: DeploymentStatusEvent
Triggered when a deployement's status changes.core :: DisjointSet
Data structure to keep track of elements partitioned into disjoint subsetsgithub :: GithubDeserializerErrors
An Error returned while deserializing objects from the APImsgpack :: MsgPackDeserializer
Deserialize MessagePack format to full Nit objectsmore_collections :: MultiHashMap
Simple way to store anHashMap[K, Array[V]]
github :: PullRequestPullCommentEvent
Triggered when a comment is created on a pull request diff.pthreads :: ReverseBlockingQueue
A collection whichis_empty
method blocks until it's empty
serialization :: SafeDeserializer
Deserialization engine limiting which types can be deserializedneo4j :: SequentialNodeCollection
A Neo4j node collection using a sequential identification scheme.ShaderVariable
instances by their name
serialization :: StrictHashMap
Maps instances to a value, usesis_same_serialized
and serialization_hash
.
# Instances of this class can be passed to `Serializer::serialize`
interface Serializable
# Serialize `self` to `serializer`
#
# This is a shortcut to `Serializer::serialize`.
fun serialize_to(serializer: Serializer) do serializer.serialize(self)
# Actual serialization of `self` to `serializer`
#
# This writes the full data of `self` to `serializer`.
#
# This method can be redefined in sub classes and refinements.
# It should use `Serializer::serialize_attribute` to to register real or
# logical attributes.
#
# Any refinement should have its equivalent refinement of
# `Deserializer::deserialize_class` to support this custom deserialization.
fun core_serialize_to(serializer: Serializer) do end
# Accept references or force direct serialization (using `serialize_to`)
#
# The subclass change the default behavior, which will accept references,
# to force to always serialize copies of `self`.
private fun serialize_to_or_delay(v: Serializer) do v.serialize_reference(self)
# 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
end
lib/serialization/serialization_core.nit:219,1--248,3
redef class Serializable
# Serialize `self` to JSON
#
# Set `plain = true` to generate standard JSON, without deserialization metadata.
# Use this option if the generated JSON will be read by other programs or humans.
# Use the default, `plain = false`, if the JSON is to be deserialized by a Nit program.
#
# Set `pretty = true` to generate pretty JSON for human eyes.
# Use the default, `pretty = false`, to generate minified JSON.
#
# This method should not be refined by subclasses,
# instead `accept_json_serializer` can customize the serialization of an object.
#
# See: `JsonSerializer`
fun serialize_to_json(plain, pretty: nullable Bool): String
do
var stream = new StringWriter
var serializer = new JsonSerializer(stream)
serializer.plain_json = plain or else false
serializer.pretty_json = pretty or else false
serializer.serialize self
stream.close
return stream.to_s
end
# Serialize `self` to plain JSON
#
# Compatibility alias for `serialize_to_json(plain=true)`.
fun to_json: String do return serialize_to_json(plain=true)
# Serialize `self` to plain pretty JSON
#
# Compatibility alias for `serialize_to_json(plain=true, pretty=true)`.
fun to_pretty_json: String do return serialize_to_json(plain=true, pretty=true)
# Refinable service to customize the serialization of this class to JSON
#
# This method can be refined to customize the serialization by either
# writing pure JSON directly on the stream `v.stream` or
# by using other services of `JsonSerializer`.
#
# Most of the time, it is preferable to refine the method `core_serialize_to`
# which is used by all the serialization engines, not just JSON.
protected fun accept_json_serializer(v: JsonSerializer)
do
v.stream.write "\{"
v.indent_level += 1
if not v.plain_json then
var id = v.cache.new_id_for(self)
v.new_line_and_indent
v.stream.write "\"__kind\": \"obj\", \"__id\": "
v.stream.write id.to_s
v.stream.write ", \"__class\": \""
v.stream.write class_name
v.stream.write "\""
end
v.serialize_core(self)
v.indent_level -= 1
v.new_line_and_indent
v.stream.write "\}"
end
end
lib/json/serialization_write.nit:199,1--262,3
redef class Serializable
# Improve the default inspection reading serializable attributes
#
# Simple immutable data are inspected as they would be written in Nit code.
#
# ~~~
# assert 123.inspect == "123"
# assert 1.5.inspect == "1.5"
# assert 0xa1u8.inspect == "0xa1u8"
# assert 'c'.inspect == "'c'"
# assert "asdf\n".inspect == "\"asdf\\n\""
# ~~~
#
# Inspections of mutable serializable objects show their dynamic type,
# their `object_id` and their first level attributes. When testing,
# the `object_id` is replaced by an id unique to each call to `inspect`.
#
# ~~~
# class MyClass
# serialize
#
# var i: Int
# var o: nullable Object
# end
#
# var class_with_null = new MyClass(123)
# assert class_with_null.to_s == class_with_null.inspect
# assert class_with_null.to_s == "<MyClass#0 i:123, o:null>"
#
# var class_with_other = new MyClass(456, class_with_null)
# assert class_with_other.to_s == "<MyClass#0 i:456, o:<MyClass#1>>"
#
# var class_with_cycle = new MyClass(789)
# class_with_cycle.o = class_with_cycle
# assert class_with_cycle.to_s == "<MyClass#0 i:789, o:<MyClass#0>>"
# ~~~
#
# Items of collections are flattened and appended to the output.
#
# ~~~
# assert [1, 2, 3].inspect == "<Array[Int]#0 [1, 2, 3]>"
#
# var set = new HashSet[Object].from([1, 1.5, "two": Object])
# assert set.inspect == """<HashSet[Object]#0 [1, 1.5, "two"]>"""
#
# var map = new Map[Int, String]
# map[1] = "one"
# map[2] = "two"
# assert map.inspect == """<HashMap[Int, String]#0 {1:"one", 2:"two"}>"""
# ~~~
#
# Inspections producing over 80 characters are cut short.
#
# ~~~
# var long_class = new MyClass(123456789, "Some " + "very "*8 + "long string")
# assert long_class.to_s == "<MyClass#0 i:123456789, o:\"Some very very very very very very very very long s…>"
# ~~~
redef fun inspect
do
var stream = new StringWriter
var serializer = new InspectSerializer(stream)
serializer.serialize self
stream.close
var str = stream.to_s
# Cut long inspects
var max_length = 80
if str.length > max_length then
str = str.substring(0, max_length-2) + "…>"
end
return str
end
private fun accept_inspect_serializer(v: InspectSerializer)
do
v.stream.write "<"
v.stream.write class_name
v.stream.write "#"
var id = object_id
if inspect_testing then id = v.cache.new_id_for(self)
v.stream.write id.to_s
accept_inspect_serializer_core v
v.stream.write ">"
end
private fun accept_inspect_serializer_core(v: InspectSerializer)
do v.serialize_core(self)
end
lib/serialization/inspect.nit:96,1--189,3
redef class Serializable
# Serialize `self` to MessagePack bytes
#
# Set `plain = true` to generate standard MessagePack, without deserialization metadata.
# Use this option if the generated MessagePack will be read by non-Nit programs.
# Use the default, `plain = false`, if the MessagePack bytes are to be deserialized by a Nit program.
fun serialize_msgpack(plain: nullable Bool): Bytes
do
var stream = new BytesWriter
stream.serialize_msgpack(self, plain)
stream.close
return stream.bytes
end
# Hook to customize the serialization of this class to MessagePack
#
# This method can be refined to customize the serialization by either
# writing pure JSON directly on the stream `v.stream` or
# by using other services of `MsgPackSerializer`.
#
# Most of the time, it is better to refine the method `core_serialize_to`
# which is used by all the serialization engines, not just MessagePack.
protected fun accept_msgpack_serializer(v: MsgPackSerializer)
do
# Count the number of attributes
var attribute_counter = new AttributeCounter
accept_msgpack_attribute_counter attribute_counter
var n_attributes = attribute_counter.count
if not v.plain_msgpack then
var n_meta_items = 2
if n_attributes > 0 then n_meta_items += 1
n_meta_items += msgpack_extra_array_items # obj+id, class_name, attributes
# Metadata
var id = v.cache.new_id_for(self)
v.stream.write_msgpack_array n_meta_items
v.stream.write_msgpack_ext(v.ext_typ_obj, id.to_bytes)
v.serialize_meta_string class_name
if n_attributes > 0 then v.stream.write_msgpack_map n_attributes
else
v.stream.write_msgpack_map n_attributes
end
v.serialize_core self
end
# Hook to customize the behavior of the `AttributeCounter`
#
# By default, this method makes `v` visits all serializable attributes.
protected fun accept_msgpack_attribute_counter(v: AttributeCounter)
do
v.serialize_core self
end
# Hook to request a larger than usual metadata array
#
# Use by `SimpleCollection` and `Map` to append the items after
# the metadata and attributes.
protected fun msgpack_extra_array_items: Int do return 0
end
lib/msgpack/serialization_write.nit:174,1--238,3
redef class Serializable
# Called by `Bundle::[]=` to dynamically choose the appropriate method according
# to the value type to store
# Non-primitive Object (`String` excluded) will be stored as a serialized json `String`
# Refine your class to customize this method behaviour
protected fun add_to_bundle(bundle: NativeBundle, key: JavaString)
do
sys.jni_env.push_local_frame(1)
var serialized_string = new StringWriter
var serializer = new JsonSerializer(serialized_string)
serializer.serialize(self)
bundle.put_string(key, serialized_string.to_s.to_java_string)
end
end
lib/android/bundle/bundle.nit:670,1--684,3