Created
June 4, 2013 13:11
-
-
Save tomchristie/5705771 to your computer and use it in GitHub Desktop.
ObjectSerializer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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