Make encoding.serialize() more programmatical

Introduce `serializable_fields` to express which class attributes
to be serialized.

Get rid of OrderedDict. Just replacing it with regular dict.

Change-Id: I3f7639dab171d3d62e92d0d1bb6d7b071cf963ad
This commit is contained in:
Alexander Gordeev
2014-05-05 15:49:03 +04:00
parent f95c8a9e6d
commit ed4460990e
5 changed files with 22 additions and 54 deletions

@ -18,9 +18,11 @@ import uuid
class Serializable(object):
"""Base class for things that can be serialized."""
serializable_fields = ()
def serialize(self):
"""Turn this object into a dict."""
raise NotImplementedError()
return dict((f, getattr(self, f)) for f in self.serializable_fields)
class RESTJSONEncoder(json.JSONEncoder):