+
+ ## Static parametized types on serializable attributes
+ for nclassdef in nmodule.n_classdefs do
+ if not nclassdef isa AStdClassdef then continue
+
+ for attribute in nclassdef.n_propdefs do
+ if not attribute isa AAttrPropdef then continue
+
+ var serialize_by_default = nclassdef.how_serialize
+ if serialize_by_default == null then continue
+ var per_attribute = not serialize_by_default
+
+ # Is `attribute` to be skipped?
+ if (per_attribute and not attribute.is_serialize) or
+ attribute.is_noserialize then continue
+
+ var mtype = attribute.mtype
+ if mtype == null then continue
+ if mtype isa MNullableType then mtype = mtype.mtype
+
+ if mtype isa MClassType and mtype.mclass.arity > 0 and
+ mtype.mclass.kind == concrete_kind and not mtype.need_anchor then
+
+ # Check is a `Serializable`
+ var mmodule = nmodule.mmodule
+ if mmodule == null then continue
+
+ var greaters = mtype.mclass.in_hierarchy(mmodule).greaters
+ var is_serializable = false
+ for sup in greaters do if sup.name == "Serializable" then
+ is_serializable = true
+ break
+ end
+
+ if is_serializable then types_to_deserialize.add mtype.to_s
+ end
+ end
+ end
+
+ # Build implementation code
+ var code = new Array[String]
+ code.add "redef fun deserialize_class_intern(name)"
+ code.add "do"
+
+ for name in types_to_deserialize do
+ code.add " if name == \"{name}\" then return new {name}.from_deserializer(self)"
+ end
+
+ code.add " return super"
+ code.add "end"
+
+ # Replace the body of the constructor
+ var npropdef = toolcontext.parse_propdef(code.join("\n")).as(AMethPropdef)
+ deserializer_npropdef.n_block = npropdef.n_block
+
+ # Run the literal phase on the generated code
+ var v = new LiteralVisitor(toolcontext)
+ v.enter_visit(npropdef.n_block)