Skip to content

Instantly share code, notes, and snippets.

@tomchristie
Created June 4, 2013 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomchristie/5705771 to your computer and use it in GitHub Desktop.
Save tomchristie/5705771 to your computer and use it in GitHub Desktop.
ObjectSerializer
class ObjectSerializer(Serializer):
def get_default_fields(self, obj, nested):
"""
Given an object, return the default set of fields to serialize.
"""
ret = SortedDict()
attrs = [key for key in obj.__dict__.keys() if not(key.startswith('_'))]
for attr in sorted(attrs):
if nested:
ret[attr] = self.__class__()
else:
ret[attr] = Field()
return ret
def get_default_field(self, obj, key, nested):
if nested:
return self.__class__()
return Field()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment