[enh] teach YunoHost how to serialize Table objects

This commit is contained in:
Laurent Peuch 2021-06-25 02:37:01 +02:00
parent c44191bc2c
commit ae93f8044e
2 changed files with 5 additions and 4 deletions

View file

@ -512,10 +512,6 @@ class Interface(BaseInterface):
import json
from moulinette.utils.serialize import JSONExtendedEncoder
# retro compat situation
if isinstance(ret, Table):
ret = ret.data
print(json.dumps(ret, cls=JSONExtendedEncoder))
else:
plain_print_dict(ret)

View file

@ -2,6 +2,8 @@ import logging
from json.encoder import JSONEncoder
import datetime
from moulinette import Table
logger = logging.getLogger("moulinette.utils.serialize")
@ -36,6 +38,9 @@ class JSONExtendedEncoder(JSONEncoder):
o = o.replace(tzinfo=pytz.utc)
return o.isoformat()
if isinstance(o, Table):
return o.data
# Return the repr for object that json can't encode
logger.warning(
"cannot properly encode in JSON the object %s, " "returned repr is: %r",