ActionScript Reflection Based JSON Validation and Conversion to VO Class

For an AIR application I had a need/desire to convert JSON generic Object instances to a tree of strongly types VO objects. The best post I could find on the subject did not go so far as to convert the Object tree to a strongly typed tree of objects that I’ve spec’d out. This post shows how I did this and I provide my conversion code.

I start with the objects that I want to generate in ActionScript:

Next is the JSON from my server:

1
2
3
4
5
6
7
8
{ "authors": [
  { "class_name": "my_author",
    "name": "John Smith",
    "physical_address": {
        "class_name": "my_address",
  "street": "123 Main Street", <br /></code></p>
  "city": "Anytown" } </code></p>
   } ]  }

Finally, here’s the code:

Comments