json formatter: all subobjects are also encoded
This commit is contained in:
parent
35dfb940c8
commit
818b756e27
1 changed files with 5 additions and 2 deletions
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
|
||||
from weboob.tools.json import json
|
||||
from weboob.capabilities.base import NotAvailable, NotLoaded
|
||||
|
||||
from .iformatter import IFormatter
|
||||
|
||||
|
|
@ -32,12 +33,14 @@ class Encoder(json.JSONEncoder):
|
|||
try:
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
except TypeError:
|
||||
if obj is NotAvailable or obj is NotLoaded:
|
||||
return None
|
||||
|
||||
try:
|
||||
dct = obj.to_dict()
|
||||
except AttributeError:
|
||||
return str(obj)
|
||||
for z in dct.itervalues():
|
||||
return z
|
||||
return dct
|
||||
|
||||
|
||||
class JsonFormatter(IFormatter):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue