The unserialization process is also quite permissive about type
definition changes, but be aware that renaming a field in a class definition after the serialization can
break the process. In general, adding fields and changing functions do not create problems.
Another important matter to note is that the unserialize() method does not invoke the class
constructor for object instances. This can have some effects on field definitions introduced after the first
serialization or other initialization code.
The following snippet shows how to serialize/deserialize an anonymous object:
class Main
{
public static function main()
{
var ob = {
name : ???John Doe???,
age : 35
};
var ser = haxe.Serializer.run(ob);
// trace something like:
// oy4:namey10:John%20Doey3:agei35g
trace(ser);
var desob : Person = haxe.Unserializer.run(ser);
trace(desob.name + ???: ??? + desob.age);
}
}
typedef Person = {
name : String,
age : Int
}
Chapter 16: haXe Advanced Topics
475
haXe Magic
Some functionalities in haXe are platform specific, others violate or at the very least circumvent the
canonical syntax definitions.
Pages:
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881