The annotation `serialize` replaces `auto_serialize` and it is also more versatile. It can annotate a module so all its class definitions are serializable. It can also annotate an attribute so only this attribute is serialized.
The `noserialize` annotation is for exceptions to `serialize`. The most common case is to mark as non-serializable an attribute such as a password or a data blob.
Pull-Request: #1389
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
# Link between two nodes and associated to a graph
class Link
- auto_serializable
+ serialize
# Type of the nodes in `graph`
type N: Node
# Result from path finding and a walkable path
class AStarPath[N]
- auto_serializable
+ serialize
# Total cost of this path
var total_cost: Int
# Context related to an evocation of pathfinding
class PathContext
- auto_serializable
+ serialize
# Type of the nodes in `graph`
type N: Node
# Warning: A* is not optimize for such a case
class ConstantPathContext
super PathContext
- auto_serializable
+ serialize
redef fun worst_cost do return 1
redef fun cost(l) do return 1
# A `PathContext` for graphs with `WeightedLink`
class WeightedPathContext
super PathContext
- auto_serializable
+ serialize
redef type L: WeightedLink
# A `Link` with a `weight`
class WeightedLink
super Link
- auto_serializable
+ serialize
# The `weight`, or cost, of this link
var weight: Int
# Advanced path conditions with customizable accept states
class TargetCondition[N: Node]
- auto_serializable
+ serialize
# Should the pathfinding accept `node` as a goal?
fun accept(node: N): Bool is abstract
# Retrieve an `Object` serialized via `[]=` function
# Returns `null` if there's no serialized object corresponding to the given key
# or if it's the wrong value type
- # Make sure that the serialized object is `auto_serializable` or that it
+ # Make sure that the serialized object is `serialize` or that it
# redefines the appropriate methods. Refer to `Serializable` documentation
# for further details
fun deserialize(key: String): nullable Object
# Retrieve an `Array` of `Object` serialized via `[]=` function
# Returns `null` if there's no serialized `Array` corresponding to the given key
# or if it's the wrong value type
- # Make sure that the serialized objects are `auto_serializable` or that they
+ # Make sure that the serialized objects are `serialize` or that they
# redefine the appropriate methods. Refer to `Serializable` documentation
# for further details
fun deserialize_array(key: String): nullable Array[nullable Object]
# Retrieve an `Object` stored via `[]=` function
#
# Returns `null` if there's no serialized object corresponding to the given key
- # Make sure that the serialized object is `auto_serializable` or that it redefines
+ # Make sure that the serialized object is `serialize` or that it redefines
# the appropriate methods. Refer to `Serializable` documentation for further details
fun [](key: String): nullable Object
do
#
# Allows for fast support of a large number of entities with rare actions,
# such as a forest with many individual trees.
-module bucketed_game
+module bucketed_game is serialize
import serialization
# Something acting on the game
class Turnable[G: Game]
- auto_serializable
# Execute `turn` for this instance.
fun do_turn(turn: GameTurn[G]) is abstract
# Something acting on the game from time to time
class Bucketable[G: Game]
super Turnable[G]
- auto_serializable
private var act_at: nullable Int = null
# Optimized organization of `Bucketable` instances
class Buckets[G: Game]
super Turnable[G]
- auto_serializable
# Bucket type used in this implementation.
type BUCKET: HashSet[Bucketable[G]]
# Event raised at the first turn
class FirstTurnEvent
super GameEvent
- auto_serializable
end
# Game logic on the client
class ThinGame
- auto_serializable
# Game tick when `self` should act.
#
# Game turn on the client
class ThinGameTurn[G: ThinGame]
- auto_serializable
# Game tick when `self` should act.
var tick: Int is protected writable
# Game turn on the full logic
class GameTurn[G: Game]
super ThinGameTurn[G]
- auto_serializable
# Game that `self` belongs to.
var game: G
# Full game logic
class Game
super ThinGame
- auto_serializable
# Game type used in this implementation.
type G: Game
# import json::serialization
#
# class Person
-# auto_serializable
+# serialize
#
# var name: String
# var year_of_birth: Int
# limitations under the License.
# Highly specific, but useful, collections-related classes.
-module more_collections
+module more_collections is serialize
import serialization
# assert m["four"] == ['i', 'i', 'i', 'i']
# assert m["zzz"] == new Array[Char]
class MultiHashMap[K, V]
- auto_serializable
super HashMap[K, Array[V]]
# Add `v` to the array associated with `k`.
# assert hm2[2, "not-two"] == null
# ~~~~
class HashMap2[K1, K2, V]
- auto_serializable
private var level1 = new HashMap[K1, HashMap[K2, V]]
# assert hm3[2, "not-two", 22] == null
# ~~~~
class HashMap3[K1, K2, K3, V]
- auto_serializable
private var level1 = new HashMap[K1, HashMap2[K2, K3, V]]
# assert dma.default == [65]
# ~~~~
class DefaultMap[K, V]
- auto_serializable
super HashMap[K, V]
# The default value.
# Abstract serialization services
-The serialization services are centered around the `auto_serializable` annotation,
+The serialization services are based on the `serialize` and the `noserialize` annotations,
the `Serializable` interface and the implementations of `Serializer` and `Deserializer`.
-## The `auto_serializable` annotation
+## The `serialize` annotation
-A class annotated with `auto_serializable` identifies it as a subclass of Serializable and
+A class annotated with `serialize` identifies it as a subclass of Serializable and
triggers the generation of customized serialization and deserialization services.
~~~
# Simple serializable class identifying a human
class Person
- auto_serializable
+ serialize
# First and last name
var name: String
The deserialized instance will not be the same instance, but they should be equal.
So, in this case, we can compare both instances with `==` to test their equality.
-Some conditions applies to the classes that can be annotated as `auto_serializable`.
+Some conditions applies to the classes that can be annotated as `serialize`.
All attributes of the class must be serializable, runtime errors will be
raised when trying to serialize non-serializable attributes.
In the class `Person`, all attributes are typed with classes the standards library.
These common types are defined defined as serializable by this project.
-The attributes could also be typed with user-defined `auto_serializable`
+The attributes could also be typed with user-defined `serialize`
classes or any other subclass of `Serializable`.
~~~
-# This `auto_serializable` class is composed of two `auto_serializable` attributes
+# This `serialize` class is composed of two `serialize` attributes
class Partnership
- auto_serializable
+ serialize
var partner_a: Person
var partner_b: Person
end
~~~
-The `auto_serializable` applies only to the class definition,
-only attributes declared locally will be serialized.
-However, each definition of a class (a refinement or specialization)
-can declare `auto_serializable`.
+### Scope of the `serialize` annotation
+
+`serialize` can annotate class definitions, modules and attributes:
+
+* The annotation on a class applies only to the class definition,
+ only attributes declared locally will be serialized.
+ However, each definition of a class (a refinement or specialization) can be annotated with `serialize`.
+
+* A module declaration annotated with `serialize` states that all its class definitions
+ and locally declared attributes are serializable.
+
+ ~~~
+ module shared_between_clients is serialize
+ ~~~
+
+* Attribute annotated with `serialize` states that it is to be serialized, when the rest of the class does not.
+ The class will become subclass to `Serializable` but its attributes are not to be serialized by default.
+ Only the attributes with the `serialize` annotation will be serialized.
+
+ ~~~
+ # Only serialize the `name`
+ class UserCredentials
+ var name: String is serialize
+ var avatar_path: String = "/somepath/"+name is lazy
+ end
+ ~~~
+
+## The `noserialize` annotation
+
+The `noserialize` annotation mark an exception in a `serialize` module or class definition.
+
+* By default a module is `noserialize`. There is no need to declare it as such.
+
+* A class definition annotated with `noserialize` within a `serialize` module will not be made serializable.
+
+* A `noserialize` attribute within a class or module annotated with `serialize` will not serialize this attribute.
+ The class will still be made subclass of `Serializable` and it won't affect the other attributes.
+ The `noserialize` attribute will not be set at deserialization.
+ Usually, it will also be annotated with `lazy` to get its value by another mean after the object has been deserialized.
+
+ ~~~
+ # Once again, only serialize the `name`
+ class UserCredentials
+ serialize
+
+ var name: String
+ var avatar_path: String = "/somepath/"+name is noserialize, lazy
+ end
+ ~~~
## Custom serializable classes
-The annotation `auto_serializable` should be enough for most cases,
+The annotation `serialize` should be enough for most cases,
but in some cases you need more control over the serialization process.
For more control, create a subclass to `Serializable` and redefine `core_serialize_to`.
### Example: the User class
-The following example cannot use the `auto_serializable` annotations
+The following example cannot use the `serialize` annotations
because some of the arguments to the `User` class need special treatment:
* The `name` attribute is perfectly normal, it can be serialized and deserialized
## Serialization services
-The `auto_serializable` annotation and the `Serializable` class are used on
+The `serialize` annotation and the `Serializable` class are used on
classes specific to the business domain.
To write (and read) instances of these classes to a persistent format
you must use implementations of `Serializer` and `Deserializer`.
* Not enough classes from the standard library are supported.
This only requires someone to actually code the support.
It should not be especially hard for most classes, some can
- simply declare the `auto_serializable` annotation.
+ simply declare the `serialize` annotation.
* A limitation of the Json parser prevents deserializing from files
with more than one object.
serialize a single object to each filesand use different instances of
serializer and deserializer each time.
-* The `auto_serializable` annotation does not handle very well
+* The `serialize` annotation does not handle very well
complex constructors. This could be improved in the compiler.
- For now, you may prefer to use `auto_serializable` on simple classes,
+ For now, you may prefer to use `serialize` on simple classes,
of by using custom `Serializable`.
* The serialization uses only the short name of a class, not its qualified name.
# Abstract services to serialize Nit objects to different formats
#
-# This module declares the `auto_serializable` annotation to mark Nit classes as serializable.
+# This module declares the `serialize` annotation to mark Nit classes as serializable.
# For an introduction to this service, refer to the documentation of the `serialization` group.
# This documentation provides more technical information on interesting entitie of this module.
#
# `notify_of_creation` must be redefined.
module serialization is
new_annotation auto_serializable
+ new_annotation serialize
+ new_annotation noserialize
end
# Abstract serialization service to be sub-classed by specialized services.
private fun place_holder_type_name: String do return "PlaceHolderTypeWhichShouldNotExist"
end
+redef class ANode
+ # Is this node annotated to be made serializable?
+ private fun is_serialize: Bool do return false
+
+ # Is this node annotated to not be made serializable?
+ private fun is_noserialize: Bool do return false
+
+ private fun accept_precise_type_visitor(v: PreciseTypeVisitor) do visit_all(v)
+end
+
+redef class ADefinition
+
+ redef fun is_serialize do
+ return get_annotations("serialize").not_empty or
+ get_annotations("auto_serializable").not_empty
+ end
+
+ redef fun is_noserialize do
+ return get_annotations("noserialize").not_empty
+ end
+end
+
# TODO add annotations on attributes (volatile, sensitive or do_not_serialize?)
private class SerializationPhasePreModel
super Phase
- redef fun process_annotated_node(nclassdef, nat)
+ redef fun process_annotated_node(node, nat)
do
# Skip if we are not interested
- if nat.n_atid.n_id.text != "auto_serializable" then return
- if not nclassdef isa AStdClassdef then
- toolcontext.error(nclassdef.location, "Syntax Error: only a concrete class can be automatically serialized.")
+ var text = nat.n_atid.n_id.text
+ var serialize = text == "auto_serializable" or text == "serialize"
+ var noserialize = text == "noserialize"
+ if not (serialize or noserialize) then return
+
+ # Check legality of annotation
+ if node isa AModuledecl then
+ if noserialize then toolcontext.error(node.location, "Syntax Error: superfluous use of `{text}`, by default a module is `{text}`")
+ return
+ else if not (node isa AStdClassdef or node isa AAttrPropdef) then
+ toolcontext.error(node.location,
+ "Syntax Error: only a class, a module or an attribute can be annotated with `{text}`.")
return
+ else if serialize and node.is_noserialize then
+ toolcontext.error(node.location,
+ "Syntax Error: an entity cannot be both `{text}` and `noserialize`.")
+ return
+ else if node.as(Prod).get_annotations(text).length > 1 then
+ toolcontext.warning(node.location, "useless-{text}",
+ "Warning: duplicated annotation `{text}`.")
end
- # Add `super Serializable`
- var sc = toolcontext.parse_superclass("Serializable")
- sc.location = nat.location
- nclassdef.n_propdefs.add sc
+ # Check the `serialize` state of the parent
+ if not node isa AModuledecl then
+ var up_serialize = false
+ var up: nullable ANode = node
+ loop
+ up = up.parent
+ if up == null then
+ break
+ else if up.is_serialize then
+ up_serialize = true
+ break
+ else if up.is_noserialize then
+ break
+ end
+ end
- generate_serialization_method(nclassdef)
+ # Check for useless double declarations
+ if serialize and up_serialize then
+ toolcontext.warning(node.location, "useless-serialize",
+ "Warning: superfluous use of `{text}`.")
+ else if noserialize and not up_serialize then
+ toolcontext.warning(node.location, "useless-noserialize",
+ "Warning: superfluous use of `{text}`.")
+ end
+ end
+ end
- generate_deserialization_init(nclassdef)
+ redef fun process_nclassdef(nclassdef)
+ do
+ if not nclassdef isa AStdClassdef then return
+
+ # Is there a declaration on the classdef or the module?
+ var serialize = nclassdef.is_serialize
+
+ if not serialize and not nclassdef.is_noserialize then
+ # Is the module marked serialize?
+ serialize = nclassdef.parent.as(AModule).is_serialize
+ end
+
+ var per_attribute = false
+ if not serialize then
+ # Is there an attribute marked serialize?
+ for npropdef in nclassdef.n_propdefs do
+ if npropdef.is_serialize then
+ serialize = true
+ per_attribute = true
+ break
+ end
+ end
+ end
+
+ if serialize then
+ # Add `super Serializable`
+ var sc = toolcontext.parse_superclass("Serializable")
+ sc.location = nclassdef.location
+ nclassdef.n_propdefs.add sc
+
+ # Add services
+ generate_serialization_method(nclassdef, per_attribute)
+ generate_deserialization_init(nclassdef, per_attribute)
+ end
end
redef fun process_nmodule(nmodule)
# collect all classes
var auto_serializable_nclassdefs = new Array[AStdClassdef]
for nclassdef in nmodule.n_classdefs do
- if nclassdef isa AStdClassdef and
- not nclassdef.get_annotations("auto_serializable").is_empty then
+ if nclassdef isa AStdClassdef and nclassdef.is_serialize then
auto_serializable_nclassdefs.add nclassdef
end
end
end
end
- fun generate_serialization_method(nclassdef: AClassdef)
+ fun generate_serialization_method(nclassdef: AClassdef, per_attribute: Bool)
do
var npropdefs = nclassdef.n_propdefs
code.add " super"
for attribute in npropdefs do if attribute isa AAttrPropdef then
+
+ # Is `attribute` to be skipped?
+ if (per_attribute and not attribute.is_serialize) or
+ attribute.is_noserialize then continue
+
var name = attribute.name
code.add " v.serialize_attribute(\"{name}\", {name})"
end
end
# Add a constructor to the automated nclassdef
- fun generate_deserialization_init(nclassdef: AStdClassdef)
+ fun generate_deserialization_init(nclassdef: AClassdef, per_attribute: Bool)
do
var npropdefs = nclassdef.n_propdefs
code.add " v.notify_of_creation self"
for attribute in npropdefs do if attribute isa AAttrPropdef then
+
+ # Is `attribute` to be skipped?
+ if (per_attribute and not attribute.is_serialize) or
+ attribute.is_noserialize then continue
+
var n_type = attribute.n_type
var type_name
if n_type == null then
redef fun visit(n) do n.accept_precise_type_visitor(self)
end
-redef class ANode
- private fun accept_precise_type_visitor(v: PreciseTypeVisitor) do visit_all(v)
-end
-
redef class AIsaExpr
redef fun accept_precise_type_visitor(v)
do
end
private var inits_to_retype = new Array[AMethPropdef]
+
+ redef fun is_serialize do return n_moduledecl != null and n_moduledecl.is_serialize
end
redef class AStdClassdef
redef class MClassType
redef fun is_visible_from(mmodule) do
- return mmodule.is_visible(mclass.intro_mmodule, public_visibility)
+ return mmodule.is_visible(mclass.intro_mmodule, mclass.visibility)
end
end
-Runtime error: Aborted (../lib/serialization/serialization.nit:109)
+Runtime error: Aborted (../lib/serialization/serialization.nit:111)
# Nit:
-<A: true a 0.123 1234 asdf false>
+<A: true a 0.123 1234 asdf false p4ssw0rd>
# Json:
{"__kind": "obj", "__id": 0, "__class": "A", "b": true, "c": {"__kind": "char", "__val": "a"}, "f": 0.123, "i": 1234, "s": "asdf", "n": null}
# Back in Nit:
-<A: true a 0.123 1234 asdf false>
+<A: true a 0.123 1234 asdf false p4ssw0rd>
# Nit:
-<B: <A: false b 123.123 2345 hjkl false> 1111 qwer>
+<B: <A: false b 123.123 2345 hjkl false p4ssw0rd> 1111 qwer>
# Json:
{"__kind": "obj", "__id": 0, "__class": "B", "b": false, "c": {"__kind": "char", "__val": "b"}, "f": 123.123, "i": 2345, "s": "hjkl", "n": null, "ii": 1111, "ss": "qwer"}
# Back in Nit:
-<B: <A: false b 123.123 2345 hjkl false> 1111 qwer>
+<B: <A: false b 123.123 2345 hjkl false p4ssw0rd> 1111 qwer>
# Nit:
-<C: <A: true a 0.123 1234 asdf false> <B: <A: false b 123.123 2345 hjkl false> 1111 qwer>>
+<C: <A: true a 0.123 1234 asdf false p4ssw0rd> <B: <A: false b 123.123 2345 hjkl false p4ssw0rd> 1111 qwer>>
# Json:
{"__kind": "obj", "__id": 0, "__class": "C", "a": {"__kind": "obj", "__id": 1, "__class": "A", "b": true, "c": {"__kind": "char", "__val": "a"}, "f": 0.123, "i": 1234, "s": "asdf", "n": null}, "b": {"__kind": "obj", "__id": 2, "__class": "B", "b": false, "c": {"__kind": "char", "__val": "b"}, "f": 123.123, "i": 2345, "s": "hjkl", "n": null, "ii": 1111, "ss": "qwer"}, "aa": {"__kind": "ref", "__id": 1}}
# Back in Nit:
-<C: <A: true a 0.123 1234 asdf false> <B: <A: false b 123.123 2345 hjkl false> 1111 qwer>>
+<C: <A: true a 0.123 1234 asdf false p4ssw0rd> <B: <A: false b 123.123 2345 hjkl false p4ssw0rd> 1111 qwer>>
# Nit:
<D: <B: <A: false b 123.123 2345 new line ->
-<- false> 1111 f"\r\/> true>
+<- false p4ssw0rd> 1111 f"\r\/> true>
# Json:
{"__kind": "obj", "__id": 0, "__class": "D", "b": false, "c": {"__kind": "char", "__val": "b"}, "f": 123.123, "i": 2345, "s": "new line ->\n<-", "n": null, "ii": 1111, "ss": "\tf\"\r\\\/", "d": {"__kind": "ref", "__id": 0}}
# Back in Nit:
<D: <B: <A: false b 123.123 2345 new line ->
-<- false> 1111 f"\r\/> true>
+<- false p4ssw0rd> 1111 f"\r\/> true>
Error: doesn't know how to deserialize class "Array"
--- /dev/null
+alt/test_serialization_alt2.nit:22,1--47,3: Warning: superfluous use of `serialize`.
+alt/test_serialization_alt2.nit:70,1--86,3: Warning: superfluous use of `auto_serializable`.
+alt/test_serialization_alt2.nit:88,1--96,3: Warning: superfluous use of `auto_serializable`.
+# Nit:
+<A: true a 0.123 1234 asdf false>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "A", "b": true, "f": 0.123, "i": 1234, "s": "asdf", "n": null, "array": {"__kind": "obj", "__id": 1, "__class": "Array", "__length": 3, "__items": [88, "hello", null]}}
+
+# Nit:
+<B: <A: false b 123.123 2345 hjkl false> 1111 qwer>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "B", "b": false, "f": 123.123, "i": 2345, "s": "hjkl", "n": null, "array": {"__kind": "obj", "__id": 1, "__class": "Array", "__length": 3, "__items": [88, "hello", null]}}
+
+# Nit:
+<C: <A: true a 0.123 1234 asdf false> <B: <A: false b 123.123 2345 hjkl false> 1111 qwer>>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "C", "a": {"__kind": "obj", "__id": 1, "__class": "A", "b": true, "f": 0.123, "i": 1234, "s": "asdf", "n": null, "array": {"__kind": "obj", "__id": 2, "__class": "Array", "__length": 3, "__items": [88, "hello", null]}}, "b": {"__kind": "obj", "__id": 3, "__class": "B", "b": false, "f": 123.123, "i": 2345, "s": "hjkl", "n": null, "array": {"__kind": "obj", "__id": 4, "__class": "Array", "__length": 3, "__items": [88, "hello", null]}}, "aa": {"__kind": "ref", "__id": 1}}
+
+# Nit:
+<D: <B: <A: false b 123.123 2345 new line ->
+<- false> 1111 f"\r\/> true>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "D", "b": false, "f": 123.123, "i": 2345, "s": "new line ->\n<-", "n": null, "array": {"__kind": "obj", "__id": 1, "__class": "Array", "__length": 3, "__items": [88, "hello", null]}, "d": {"__kind": "ref", "__id": 0}}
+
--- /dev/null
+alt/test_serialization_alt3.nit:49,1--68,3: Warning: superfluous use of `noserialize`.
+# Nit:
+<A: true a 0.123 1234 asdf false>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "A", "b": true, "c": {"__kind": "char", "__val": "a"}, "f": 0.123, "i": 1234, "s": "asdf", "n": null, "array": {"__kind": "obj", "__id": 1, "__class": "Array", "__length": 3, "__items": [88, "hello", null]}}
+
+# Nit:
+<B: <A: false b 123.123 2345 hjkl false> 1111 qwer>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "B", "b": false, "c": {"__kind": "char", "__val": "b"}, "f": 123.123, "i": 2345, "s": "hjkl", "n": null, "array": {"__kind": "obj", "__id": 1, "__class": "Array", "__length": 3, "__items": [88, "hello", null]}}
+
+# Nit:
+<C: <A: true a 0.123 1234 asdf false> <B: <A: false b 123.123 2345 hjkl false> 1111 qwer>>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "C", "a": {"__kind": "obj", "__id": 1, "__class": "A", "b": true, "c": {"__kind": "char", "__val": "a"}, "f": 0.123, "i": 1234, "s": "asdf", "n": null, "array": {"__kind": "obj", "__id": 2, "__class": "Array", "__length": 3, "__items": [88, "hello", null]}}, "b": {"__kind": "obj", "__id": 3, "__class": "B", "b": false, "c": {"__kind": "char", "__val": "b"}, "f": 123.123, "i": 2345, "s": "hjkl", "n": null, "array": {"__kind": "obj", "__id": 4, "__class": "Array", "__length": 3, "__items": [88, "hello", null]}}, "aa": {"__kind": "ref", "__id": 1}}
+
+# Nit:
+<D: <B: <A: false b 123.123 2345 new line ->
+<- false> 1111 f"\r\/> true>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "D", "b": false, "c": {"__kind": "char", "__val": "b"}, "f": 123.123, "i": 2345, "s": "new line ->\n<-", "n": null, "array": {"__kind": "obj", "__id": 1, "__class": "Array", "__length": 3, "__items": [88, "hello", null]}, "d": {"__kind": "ref", "__id": 0}}
+
--- /dev/null
+alt/test_serialization_alt4.nit:29,2--31,26: Warning: superfluous use of `serialize`.
+# Nit:
+<A: true a 0.123 1234 asdf false>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "A", "b": true, "c": {"__kind": "char", "__val": "a"}, "f": 0.123, "i": 1234, "s": "asdf", "n": null, "array": {"__kind": "obj", "__id": 1, "__class": "Array", "__length": 3, "__items": [88, "hello", null]}}
+
+# Nit:
+<B: <A: false b 123.123 2345 hjkl false> 1111 qwer>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "B", "b": false, "c": {"__kind": "char", "__val": "b"}, "f": 123.123, "i": 2345, "s": "hjkl", "n": null, "array": {"__kind": "obj", "__id": 1, "__class": "Array", "__length": 3, "__items": [88, "hello", null]}, "ii": 1111, "ss": "qwer"}
+
+# Nit:
+<C: <A: true a 0.123 1234 asdf false> <B: <A: false b 123.123 2345 hjkl false> 1111 qwer>>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "C", "a": {"__kind": "obj", "__id": 1, "__class": "A", "b": true, "c": {"__kind": "char", "__val": "a"}, "f": 0.123, "i": 1234, "s": "asdf", "n": null, "array": {"__kind": "obj", "__id": 2, "__class": "Array", "__length": 3, "__items": [88, "hello", null]}}, "b": {"__kind": "obj", "__id": 3, "__class": "B", "b": false, "c": {"__kind": "char", "__val": "b"}, "f": 123.123, "i": 2345, "s": "hjkl", "n": null, "array": {"__kind": "obj", "__id": 4, "__class": "Array", "__length": 3, "__items": [88, "hello", null]}, "ii": 1111, "ss": "qwer"}, "aa": {"__kind": "ref", "__id": 1}}
+
+# Nit:
+<D: <B: <A: false b 123.123 2345 new line ->
+<- false> 1111 f"\r\/> true>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "D", "b": false, "c": {"__kind": "char", "__val": "b"}, "f": 123.123, "i": 2345, "s": "new line ->\n<-", "n": null, "array": {"__kind": "obj", "__id": 1, "__class": "Array", "__length": 3, "__items": [88, "hello", null]}, "ii": 1111, "ss": "\tf\"\r\\\/", "d": {"__kind": "ref", "__id": 0}}
+
--- /dev/null
+alt/test_serialization_alt5.nit:22,1--47,3: Warning: duplicated annotation `serialize`.
+# Nit:
+<A: true a 0.123 1234 asdf false>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "A", "b": true, "c": {"__kind": "char", "__val": "a"}, "f": 0.123, "i": 1234, "s": "asdf", "n": null, "array": {"__kind": "obj", "__id": 1, "__class": "Array", "__length": 3, "__items": [88, "hello", null]}}
+
+# Nit:
+<B: <A: false b 123.123 2345 hjkl false> 1111 qwer>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "B", "b": false, "c": {"__kind": "char", "__val": "b"}, "f": 123.123, "i": 2345, "s": "hjkl", "n": null, "array": {"__kind": "obj", "__id": 1, "__class": "Array", "__length": 3, "__items": [88, "hello", null]}, "ii": 1111, "ss": "qwer"}
+
+# Nit:
+<C: <A: true a 0.123 1234 asdf false> <B: <A: false b 123.123 2345 hjkl false> 1111 qwer>>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "C", "a": {"__kind": "obj", "__id": 1, "__class": "A", "b": true, "c": {"__kind": "char", "__val": "a"}, "f": 0.123, "i": 1234, "s": "asdf", "n": null, "array": {"__kind": "obj", "__id": 2, "__class": "Array", "__length": 3, "__items": [88, "hello", null]}}, "b": {"__kind": "obj", "__id": 3, "__class": "B", "b": false, "c": {"__kind": "char", "__val": "b"}, "f": 123.123, "i": 2345, "s": "hjkl", "n": null, "array": {"__kind": "obj", "__id": 4, "__class": "Array", "__length": 3, "__items": [88, "hello", null]}, "ii": 1111, "ss": "qwer"}, "aa": {"__kind": "ref", "__id": 1}}
+
+# Nit:
+<D: <B: <A: false b 123.123 2345 new line ->
+<- false> 1111 f"\r\/> true>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "D", "b": false, "c": {"__kind": "char", "__val": "b"}, "f": 123.123, "i": 2345, "s": "new line ->\n<-", "n": null, "array": {"__kind": "obj", "__id": 1, "__class": "Array", "__length": 3, "__items": [88, "hello", null]}, "ii": 1111, "ss": "\tf\"\r\\\/", "d": {"__kind": "ref", "__id": 0}}
+
# Nit:
-<A: true a 0.123 1234 asdf false>
+<A: true a 0.123 1234 asdf false p4ssw0rd>
# Json:
{"__kind": "obj", "__id": 0, "__class": "A", "b": true, "c": {"__kind": "char", "__val": "a"}, "f": 0.123, "i": 1234, "s": "asdf", "n": null}
# Back in Nit:
-<A: true a 0.123 1234 asdf false>
+<A: true a 0.123 1234 asdf false p4ssw0rd>
# Nit:
-<B: <A: false b 123.123 2345 hjkl false> 1111 qwer>
+<B: <A: false b 123.123 2345 hjkl false p4ssw0rd> 1111 qwer>
# Json:
{"__kind": "obj", "__id": 0, "__class": "B", "b": false, "c": {"__kind": "char", "__val": "b"}, "f": 123.123, "i": 2345, "s": "hjkl", "n": null, "ii": 1111, "ss": "qwer"}
# Back in Nit:
-<B: <A: false b 123.123 2345 hjkl false> 1111 qwer>
+<B: <A: false b 123.123 2345 hjkl false p4ssw0rd> 1111 qwer>
# Nit:
-<C: <A: true a 0.123 1234 asdf false> <B: <A: false b 123.123 2345 hjkl false> 1111 qwer>>
+<C: <A: true a 0.123 1234 asdf false p4ssw0rd> <B: <A: false b 123.123 2345 hjkl false p4ssw0rd> 1111 qwer>>
# Json:
{"__kind": "obj", "__id": 0, "__class": "C", "a": {"__kind": "obj", "__id": 1, "__class": "A", "b": true, "c": {"__kind": "char", "__val": "a"}, "f": 0.123, "i": 1234, "s": "asdf", "n": null}, "b": {"__kind": "obj", "__id": 2, "__class": "B", "b": false, "c": {"__kind": "char", "__val": "b"}, "f": 123.123, "i": 2345, "s": "hjkl", "n": null, "ii": 1111, "ss": "qwer"}, "aa": {"__kind": "ref", "__id": 1}}
# Back in Nit:
-<C: <A: true a 0.123 1234 asdf false> <B: <A: false b 123.123 2345 hjkl false> 1111 qwer>>
+<C: <A: true a 0.123 1234 asdf false p4ssw0rd> <B: <A: false b 123.123 2345 hjkl false p4ssw0rd> 1111 qwer>>
# Nit:
<D: <B: <A: false b 123.123 2345 new line ->
-<- false> 1111 f"\r\/> true>
+<- false p4ssw0rd> 1111 f"\r\/> true>
# Json:
{"__kind": "obj", "__id": 0, "__class": "D", "b": false, "c": {"__kind": "char", "__val": "b"}, "f": 123.123, "i": 2345, "s": "new line ->\n<-", "n": null, "ii": 1111, "ss": "\tf\"\r\\\/", "d": {"__kind": "ref", "__id": 0}}
# Back in Nit:
<D: <B: <A: false b 123.123 2345 new line ->
-<- false> 1111 f"\r\/> true>
+<- false p4ssw0rd> 1111 f"\r\/> true>
# Nit:
-<A: true a 0.123 1234 asdf false>
+<A: true a 0.123 1234 asdf false p4ssw0rd>
# Json:
{"__kind": "obj", "__id": 0, "__class": "A", "b": true, "c": {"__kind": "char", "__val": "a"}, "f": 0.123, "i": 1234, "s": "asdf", "n": null}
# Back in Nit:
-<A: true a 0.123 1234 asdf false>
+<A: true a 0.123 1234 asdf false p4ssw0rd>
# Nit:
-<B: <A: false b 123.123 2345 hjkl false> 1111 qwer>
+<B: <A: false b 123.123 2345 hjkl false p4ssw0rd> 1111 qwer>
# Json:
{"__kind": "obj", "__id": 0, "__class": "B", "b": false, "c": {"__kind": "char", "__val": "b"}, "f": 123.123, "i": 2345, "s": "hjkl", "n": null, "ii": 1111, "ss": "qwer"}
# Back in Nit:
-<B: <A: false b 123.123 2345 hjkl false> 1111 qwer>
+<B: <A: false b 123.123 2345 hjkl false p4ssw0rd> 1111 qwer>
# Nit:
-<C: <A: true a 0.123 1234 asdf false> <B: <A: false b 123.123 2345 hjkl false> 1111 qwer>>
+<C: <A: true a 0.123 1234 asdf false p4ssw0rd> <B: <A: false b 123.123 2345 hjkl false p4ssw0rd> 1111 qwer>>
# Json:
{"__kind": "obj", "__id": 0, "__class": "C", "a": {"__kind": "obj", "__id": 1, "__class": "A", "b": true, "c": {"__kind": "char", "__val": "a"}, "f": 0.123, "i": 1234, "s": "asdf", "n": null}, "b": {"__kind": "obj", "__id": 2, "__class": "B", "b": false, "c": {"__kind": "char", "__val": "b"}, "f": 123.123, "i": 2345, "s": "hjkl", "n": null, "ii": 1111, "ss": "qwer"}, "aa": {"__kind": "ref", "__id": 1}}
# Back in Nit:
-<C: <A: true a 0.123 1234 asdf false> <B: <A: false b 123.123 2345 hjkl false> 1111 qwer>>
+<C: <A: true a 0.123 1234 asdf false p4ssw0rd> <B: <A: false b 123.123 2345 hjkl false p4ssw0rd> 1111 qwer>>
# Nit:
<D: <B: <A: false b 123.123 2345 new line ->
-<- false> 1111 f"\r\/> true>
+<- false p4ssw0rd> 1111 f"\r\/> true>
# Json:
{"__kind": "obj", "__id": 0, "__class": "D", "b": false, "c": {"__kind": "char", "__val": "b"}, "f": 123.123, "i": 2345, "s": "new line ->\n<-", "n": null, "ii": 1111, "ss": "\tf\"\r\\\/", "d": {"__kind": "ref", "__id": 0}}
# Back in Nit:
<D: <B: <A: false b 123.123 2345 new line ->
-<- false> 1111 f"\r\/> true>
+<- false p4ssw0rd> 1111 f"\r\/> true>
# Nit:
<E: a: hello, 1234, 123.4; b: hella, 2345, 234.5>
# Nit:
-<A: true a 0.123 1234 asdf false>
+<A: true a 0.123 1234 asdf false p4ssw0rd>
# Json:
{"b": true, "c": "a", "f": 0.123, "i": 1234, "s": "asdf", "n": null}
# Nit:
-<B: <A: false b 123.123 2345 hjkl false> 1111 qwer>
+<B: <A: false b 123.123 2345 hjkl false p4ssw0rd> 1111 qwer>
# Json:
{"b": false, "c": "b", "f": 123.123, "i": 2345, "s": "hjkl", "n": null, "ii": 1111, "ss": "qwer"}
# Nit:
-<C: <A: true a 0.123 1234 asdf false> <B: <A: false b 123.123 2345 hjkl false> 1111 qwer>>
+<C: <A: true a 0.123 1234 asdf false p4ssw0rd> <B: <A: false b 123.123 2345 hjkl false p4ssw0rd> 1111 qwer>>
# Json:
{"a": {"b": true, "c": "a", "f": 0.123, "i": 1234, "s": "asdf", "n": null}, "b": {"b": false, "c": "b", "f": 123.123, "i": 2345, "s": "hjkl", "n": null, "ii": 1111, "ss": "qwer"}, "aa": {"b": true, "c": "a", "f": 0.123, "i": 1234, "s": "asdf", "n": null}}
# Nit:
<D: <B: <A: false b 123.123 2345 new line ->
-<- false> 1111 f"\r\/> true>
+<- false p4ssw0rd> 1111 f"\r\/> true>
# Json:
{"b": false, "c": "b", "f": 123.123, "i": 2345, "s": "new line ->\n<-", "n": null, "ii": 1111, "ss": "\tf\"\r\\\/", "d": null}
--- /dev/null
+alt/test_serialization_alt2.nit:22,1--47,3: Warning: superfluous use of `serialize`.
+alt/test_serialization_alt2.nit:70,1--86,3: Warning: superfluous use of `auto_serializable`.
+alt/test_serialization_alt2.nit:88,1--96,3: Warning: superfluous use of `auto_serializable`.
+# Nit:
+<A: true a 0.123 1234 asdf false>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "A", "b": true, "f": 0.123, "i": 1234, "s": "asdf", "n": null, "array": {"__kind": "obj", "__id": 1, "__class": "Array[nullable Object]", "__length": 3, "__items": [88, "hello", null]}}
+
+# Nit:
+<B: <A: false b 123.123 2345 hjkl false> 1111 qwer>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "B", "b": false, "f": 123.123, "i": 2345, "s": "hjkl", "n": null, "array": {"__kind": "obj", "__id": 1, "__class": "Array[nullable Object]", "__length": 3, "__items": [88, "hello", null]}}
+
+# Nit:
+<C: <A: true a 0.123 1234 asdf false> <B: <A: false b 123.123 2345 hjkl false> 1111 qwer>>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "C", "a": {"__kind": "obj", "__id": 1, "__class": "A", "b": true, "f": 0.123, "i": 1234, "s": "asdf", "n": null, "array": {"__kind": "obj", "__id": 2, "__class": "Array[nullable Object]", "__length": 3, "__items": [88, "hello", null]}}, "b": {"__kind": "obj", "__id": 3, "__class": "B", "b": false, "f": 123.123, "i": 2345, "s": "hjkl", "n": null, "array": {"__kind": "obj", "__id": 4, "__class": "Array[nullable Object]", "__length": 3, "__items": [88, "hello", null]}}, "aa": {"__kind": "ref", "__id": 1}}
+
+# Nit:
+<D: <B: <A: false b 123.123 2345 new line ->
+<- false> 1111 f"\r\/> true>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "D", "b": false, "f": 123.123, "i": 2345, "s": "new line ->\n<-", "n": null, "array": {"__kind": "obj", "__id": 1, "__class": "Array[nullable Object]", "__length": 3, "__items": [88, "hello", null]}, "d": {"__kind": "ref", "__id": 0}}
+
--- /dev/null
+alt/test_serialization_alt3.nit:49,1--68,3: Warning: superfluous use of `noserialize`.
+# Nit:
+<A: true a 0.123 1234 asdf false>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "A", "b": true, "c": {"__kind": "char", "__val": "a"}, "f": 0.123, "i": 1234, "s": "asdf", "n": null, "array": {"__kind": "obj", "__id": 1, "__class": "Array[nullable Object]", "__length": 3, "__items": [88, "hello", null]}}
+
+# Nit:
+<B: <A: false b 123.123 2345 hjkl false> 1111 qwer>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "B", "b": false, "c": {"__kind": "char", "__val": "b"}, "f": 123.123, "i": 2345, "s": "hjkl", "n": null, "array": {"__kind": "obj", "__id": 1, "__class": "Array[nullable Object]", "__length": 3, "__items": [88, "hello", null]}}
+
+# Nit:
+<C: <A: true a 0.123 1234 asdf false> <B: <A: false b 123.123 2345 hjkl false> 1111 qwer>>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "C", "a": {"__kind": "obj", "__id": 1, "__class": "A", "b": true, "c": {"__kind": "char", "__val": "a"}, "f": 0.123, "i": 1234, "s": "asdf", "n": null, "array": {"__kind": "obj", "__id": 2, "__class": "Array[nullable Object]", "__length": 3, "__items": [88, "hello", null]}}, "b": {"__kind": "obj", "__id": 3, "__class": "B", "b": false, "c": {"__kind": "char", "__val": "b"}, "f": 123.123, "i": 2345, "s": "hjkl", "n": null, "array": {"__kind": "obj", "__id": 4, "__class": "Array[nullable Object]", "__length": 3, "__items": [88, "hello", null]}}, "aa": {"__kind": "ref", "__id": 1}}
+
+# Nit:
+<D: <B: <A: false b 123.123 2345 new line ->
+<- false> 1111 f"\r\/> true>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "D", "b": false, "c": {"__kind": "char", "__val": "b"}, "f": 123.123, "i": 2345, "s": "new line ->\n<-", "n": null, "array": {"__kind": "obj", "__id": 1, "__class": "Array[nullable Object]", "__length": 3, "__items": [88, "hello", null]}, "d": {"__kind": "ref", "__id": 0}}
+
--- /dev/null
+alt/test_serialization_alt4.nit:29,2--31,26: Warning: superfluous use of `serialize`.
+# Nit:
+<A: true a 0.123 1234 asdf false>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "A", "b": true, "c": {"__kind": "char", "__val": "a"}, "f": 0.123, "i": 1234, "s": "asdf", "n": null, "array": {"__kind": "obj", "__id": 1, "__class": "Array[nullable Object]", "__length": 3, "__items": [88, "hello", null]}}
+
+# Nit:
+<B: <A: false b 123.123 2345 hjkl false> 1111 qwer>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "B", "b": false, "c": {"__kind": "char", "__val": "b"}, "f": 123.123, "i": 2345, "s": "hjkl", "n": null, "array": {"__kind": "obj", "__id": 1, "__class": "Array[nullable Object]", "__length": 3, "__items": [88, "hello", null]}, "ii": 1111, "ss": "qwer"}
+
+# Nit:
+<C: <A: true a 0.123 1234 asdf false> <B: <A: false b 123.123 2345 hjkl false> 1111 qwer>>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "C", "a": {"__kind": "obj", "__id": 1, "__class": "A", "b": true, "c": {"__kind": "char", "__val": "a"}, "f": 0.123, "i": 1234, "s": "asdf", "n": null, "array": {"__kind": "obj", "__id": 2, "__class": "Array[nullable Object]", "__length": 3, "__items": [88, "hello", null]}}, "b": {"__kind": "obj", "__id": 3, "__class": "B", "b": false, "c": {"__kind": "char", "__val": "b"}, "f": 123.123, "i": 2345, "s": "hjkl", "n": null, "array": {"__kind": "obj", "__id": 4, "__class": "Array[nullable Object]", "__length": 3, "__items": [88, "hello", null]}, "ii": 1111, "ss": "qwer"}, "aa": {"__kind": "ref", "__id": 1}}
+
+# Nit:
+<D: <B: <A: false b 123.123 2345 new line ->
+<- false> 1111 f"\r\/> true>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "D", "b": false, "c": {"__kind": "char", "__val": "b"}, "f": 123.123, "i": 2345, "s": "new line ->\n<-", "n": null, "array": {"__kind": "obj", "__id": 1, "__class": "Array[nullable Object]", "__length": 3, "__items": [88, "hello", null]}, "ii": 1111, "ss": "\tf\"\r\\\/", "d": {"__kind": "ref", "__id": 0}}
+
--- /dev/null
+alt/test_serialization_alt5.nit:22,1--47,3: Warning: duplicated annotation `serialize`.
+# Nit:
+<A: true a 0.123 1234 asdf false>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "A", "b": true, "c": {"__kind": "char", "__val": "a"}, "f": 0.123, "i": 1234, "s": "asdf", "n": null, "array": {"__kind": "obj", "__id": 1, "__class": "Array[nullable Object]", "__length": 3, "__items": [88, "hello", null]}}
+
+# Nit:
+<B: <A: false b 123.123 2345 hjkl false> 1111 qwer>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "B", "b": false, "c": {"__kind": "char", "__val": "b"}, "f": 123.123, "i": 2345, "s": "hjkl", "n": null, "array": {"__kind": "obj", "__id": 1, "__class": "Array[nullable Object]", "__length": 3, "__items": [88, "hello", null]}, "ii": 1111, "ss": "qwer"}
+
+# Nit:
+<C: <A: true a 0.123 1234 asdf false> <B: <A: false b 123.123 2345 hjkl false> 1111 qwer>>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "C", "a": {"__kind": "obj", "__id": 1, "__class": "A", "b": true, "c": {"__kind": "char", "__val": "a"}, "f": 0.123, "i": 1234, "s": "asdf", "n": null, "array": {"__kind": "obj", "__id": 2, "__class": "Array[nullable Object]", "__length": 3, "__items": [88, "hello", null]}}, "b": {"__kind": "obj", "__id": 3, "__class": "B", "b": false, "c": {"__kind": "char", "__val": "b"}, "f": 123.123, "i": 2345, "s": "hjkl", "n": null, "array": {"__kind": "obj", "__id": 4, "__class": "Array[nullable Object]", "__length": 3, "__items": [88, "hello", null]}, "ii": 1111, "ss": "qwer"}, "aa": {"__kind": "ref", "__id": 1}}
+
+# Nit:
+<D: <B: <A: false b 123.123 2345 new line ->
+<- false> 1111 f"\r\/> true>
+
+# Json:
+{"__kind": "obj", "__id": 0, "__class": "D", "b": false, "c": {"__kind": "char", "__val": "b"}, "f": 123.123, "i": 2345, "s": "new line ->\n<-", "n": null, "array": {"__kind": "obj", "__id": 1, "__class": "Array[nullable Object]", "__length": 3, "__items": [88, "hello", null]}, "ii": 1111, "ss": "\tf\"\r\\\/", "d": {"__kind": "ref", "__id": 0}}
+
var i = 123
var s = "asdf"
var n: nullable Int
+ var password = "p4ssw0rd" is lazy, noserialize
init(b: Bool, c: Char, f: Float, i: Int, s: String, n: nullable Int)
do
self.s = s
end
- redef fun to_s do return "<A: {b} {c} {f} {i} {s} {n != null}>"
+ redef fun to_s do return "<A: {b} {c} {f} {i} {s} {n != null} {password}>"
end
# Sub-class of A
# See the License for the specific language governing permissions and
# limitations under the License.
+#alt2#module test_serialization_alt2 is serialize
+
import serialization
import json::serialization
# Simple class
class A
- auto_serializable
+ serialize
+#alt5# serialize
var b = false
- var c: Char
- var f: Float
+ var c: Char#alt2#
+ #alt2#var c: Char is noserialize
+ var f: Float#alt4#
+ #alt4#var f: Float is serialize
var i = 123
var s = "asdf"
var n: nullable Int
# Sub-class of A
class B
- auto_serializable
+ auto_serializable#alt2##alt3#
+#alt2# noserialize
+#alt3# noserialize
super A
var ii: Int