If we want to serialize objects we must consider two questions:
- What to serialize? Which fields of objects, how deep to serialize related objects.
- How output should looks like? Which format (xml, json, yaml), fields renaming, some format specific options (like attributes in xml - nothing similar in json), order of fields, some fields in other place in structure tree than others.
This questions lead as to two phases of serialization:
- First phase "dehydration": Change class instances (generally Python class, particular Django Model class) to dictionary contains data(python native types) of all interesting us fields. In this stage we are not interested in specific format.