[noob question]
What’s the simplest way to encode a class into JSON in python running on GAE? Not using Django and just whatever built-in stuff that GAE has.
My class is defined like this:
class Sample:
def __init__(self, myName, myEmail, myLocality, myAliases, myRoles):
self.name = myName;
self.email = myEmail;
self.locality = myLocality
self.aliases = myAliases; # this is a list of strings
self.roles = myRoles # this is a dictionary
I want to transform it so it looks like this in json:
{sample:
name: "a name value",
email: "whatever email value",
aliases: [alias1, alias2, alias3],
locality: "some locality value",
roles: {
name: "some name value",
type: "some type value",
aux: "additional information"
}
}
I plan to return this as the response data for the request.
Do I need to come up with a custom Encoder class for my ‘Sample’ class?
How about this: