I'm using Colander to convert JSON strings to Python Objects and vice versa in a Pyramid/Cornice based project.
Is there any way that you can serialize/deserialize to different names/keys ?
Here is the Colander Schema:
class CommentSchema(MappingSchema):
resource_id = SchemaNode(Int(), name="resourceID", location="body")
text = SchemaNode(String(), name="text", location="body")
And here is the input JSON
{"text":"Hello!", "resourceID":12}
It is being converted to :
{u'text': u'Hello!', u'resourceID': 12}
Here is my question, can I have the same input JSON converted to the following?
{u'full_text': u'Hello!', u'resource_id': 12}
Thanks for your help.
I eventually had to do it manually. Whatever is received from the JSON is used to construct a Data Object. The Object would have a custom function to map the data to the desired output format, and you pass the output to the serializer:
And the DataObject would look like this: