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:
ironic_python_agent
@ -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):
|
||||
|
Reference in New Issue
Block a user