The real issue in doing it automatically is that there is no means in
a class to resolve a getDefinitionByName call if the named class is
not imported, so you have to provide your own "getDefinitionByName",
AKA a resolver object, where you register your classes by name and the
pass to the decoder for it to resolve class definitions.
In the end, encoding is almost the same (a part of Date -> String
conversion) but decoding accounts to a method like
JSON.encode2(string, targetClass, resolver) (the result should be of
the class targetClass)
If anyone is interested, I could post the classes, or merge them in
some developer branch.
Best regards,
Saverio
YourClass constructor will have to basically take values from the
Object (returned by JSON.decode(stuff)) and set it to its properties
right ?
Thanks,
Shankar K
Appreciate if you can pass on your code that can decode JSON to a
custom class.. Btw, i have used Vectors in my AS class, will that be a
problem ?
Thanks,
Shankar
The whole point is to not have a special constructor (actually classes
should have an empty constructor, like in AMF3 case).
I am not sure about the vector matter.
Answering to a previous question, the point is not having the classes
doing the parsing, but only (as much as possible) giving type
information. That's why it's necessary to declare the
[ArrayElementType] for array properties (and to keep that metadata for
runtime).
On the other side, it's not possible to use Vector as an actual
generic (in the Java sense), like
var c:Class = getClass();
var v:Vector.<c>;
this raises an error, because vector type must be a compile-time
constant.
If you have any idea on solving this problem, I'll correct it and post
the corrected version.
OTOH, I found a problem wrt the [Transient] properties, sometimes
they're being serialized... I have to look for the origin of this
problem before posting the code.
Best regards,
Saverio