Closed thomasuster closed 9 years ago
This appears to be a fundamental problem with serialization of Class types. eg:
class Test
{
public static function main():Void
{
var t = Test;
trace( t == haxe.Unserializer.run( haxe.Serializer.run(t) ) );
}
}
Throws on neko and fails on hxcpp. Did you say it was working earlier? It may have been silently failing. I think saving the class name, rather than Class<Dynamic>
is the only way serialization is going to work for now.
Reported over in haxe: https://github.com/HaxeFoundation/haxe/issues/3715
Before it would omit class references, but the rest of the fields would serialize / unserialize correctly. I use this a lot for making prototypical instances.
Get copy with most fields
var instance = Unserializer.run(Serializer.run(proto));
Set class refs since they silently get omitted
instance.classReference = proto.classReference;
When I actually need to serialize class references then I override hxSerialize/hxUnSerialize. But like you said, it would be awesome if that worked instead of silently omitting.
I have fixed this in the haxe git code. You may be able to copy the haxe.Serialize/Unserialize from the git repo and have it work. I will think about whether I should offer control over silent failing on cases similar to this.
Unserializing class references explodes "exception thrown : Invalid Cast".
I created a boiled down test.
Commit https://github.com/thomasuster/hxcpp/commit/b330ed3b152b9d1cf8d2ce6d94344d4b4989246e Branch https://github.com/thomasuster/hxcpp/tree/master_classRef_serialization