reflection-based de/serializer

Monkey Forums/Monkey Programming/reflection-based de/serializer

Nobuyuki(Posted 2012) [#1]
Now that Monkey has a module to support Reflection, would it be technically feasible (and relatively straightforward) to write a serializer leveraging it?

Mainly, I am thinking of a way to inspect and tokenize various JSON types into monkey equivalents (or even generic containers), and stuff them into a class based on matching tag identifiers. However, I haven't tested out the reflection module yet, and don't know if it breaks or changes any of Monkey's default behavior by including it in a project, or if the functionality even extends far enough to accomplish a general deserializer.

Right now I'm using Warpy's JSON class to get objects I serialized from .net's JsonDataContractSerializer into Monkey, but that requires a lot of manual finagling (and casts upon casts upon casts!). Warpy said a while back that having Reflection would solve a lot of these problems, but in the interim since Reflection was added to the language, I haven't seen anyone (not even the diddy guys, afaik) attempt to write one.

What would such an undertaking involve, and are there any potential pitfalls and gotchas to implementing it in Monkey at its current state?


slenkar(Posted 2012) [#2]
Ive got one here:
http://monkeycoder.co.nz/Community/posts.php?topic=2487

but it uses XML style output instead of JSON

its not too hard to change it to JSON if you want to


Nobuyuki(Posted 2012) [#3]
Thanks muchly. I don't know what this reflection filter is yet (I'm guessing some sort of compiler directive to avoid recursion loops or something), but I'll be sure to check into it.


slenkar(Posted 2012) [#4]
the reflection filter is used to tell monkey which classes to reflect,