Allow for custom objects types in JSON
Brought to you by:
charliehubbard
Let's say I have a class:
class Person {
String firstName;
String lastName;
}
... and it's a member of an object defined by the following class:
class People {
Person husband;
Perseon wife;
}
It would be very cool if I had an instance of People and could get something like you get for a date for the Person fields... in other words, in the returned JSON I'd see something like:
{ "people" : { "husband" : new Person("xxx", "yyy"), "wife" : new Peson("xxx", "yyy") } }
...where xxx and yyy is the firstName and lastName fields of the Person class. Then, assuming there is a Person class available on the client in global scope, I'd get an instance of it. My syntax might be a little off there, but you get the idea.
This isn't valid JSON. It will work if you use eval(), but there are dangers in doing that approach. I could hack one side of the conversation and inject my own classes to instantiate causing a serious security hole. This isn't going to be done because of these two reasons.