[haXe] Support for substitution in Unserializer

Nicolas Cannasse ncannasse at motion-twin.com
Fri Dec 7 12:26:51 CET 2007


Michael Pliskin a écrit :
> Hello list,
> 
>   I've just met an issue and I wonder if a general solution for it
>   might be of any use. I used an enum for a long time to serialize
>   some data and put it into database, and then I changed the enum
>   declaration - and now I cannot read my old data (I changed parameter
>   lists for some constructors). The way I am now planning to
>   workaround it is to write a simple converter taking old data,
>   deserializing it using old enum (using neko.Boot.getClasses() trick
>   to replace enum instance I described in my previous post), then
>   constructing a new enum and serializing it back. However, this
>   requires some magic and is clearly not too easy - I am thinking -
>   would it make sense to have some kind of 'substitution table' in
>   Unserializer, so whenever it instantiantes a class or an enum, it
>   looks there for a proper thing to instantiate.

I think that you can redefine haxe.Unserializer.DEFAULT_RESOLVER in
order to customize the you you're looking up your enum, and for example
when MyEnum is requested you can return MyEnumOldVersion, which enable
you to unserialize old data. Then you'll have to convert by hand your
data to new version and serialize again. The only thing is that you'll
have to modify all your data one at-a-time.

Best,
Nicolas



More information about the Haxe mailing list