From f15758dbea6be0894cdc2fcc19ec9d2428c797f1 Mon Sep 17 00:00:00 2001 From: Pavel Zuna Date: Tue, 10 Aug 2010 16:40:00 -0400 Subject: Improve serialization to JSON. - Make it recursive. - Make Param classes serializable. - Take python native data types into account. --- ipalib/parameters.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'ipalib/parameters.py') diff --git a/ipalib/parameters.py b/ipalib/parameters.py index c86db758..234ceff7 100644 --- a/ipalib/parameters.py +++ b/ipalib/parameters.py @@ -852,6 +852,20 @@ class Param(ReadOnly): pass return self.default + def __json__(self): + json_dict = {} + for (a, k, d) in self.kwargs: + if k in (callable, DefaultFrom): + continue + elif isinstance(getattr(self, a), frozenset): + json_dict[a] = [k for k in getattr(self, a, [])] + else: + json_dict[a] = getattr(self, a, '') + json_dict['class'] = self.__class__.__name__ + json_dict['name'] = self.name + json_dict['type'] = self.type.__name__ + return json_dict + class Bool(Param): """ -- cgit