cic-internal-integration/apps/cic-eth/cic_eth/server/encoder.py

21 lines
608 B
Python
Raw Normal View History

2021-11-12 09:14:40 +01:00
from connexion.apps.flask_app import FlaskJSONEncoder
import six
from cic_eth.server.models.base_model_ import Model
class JSONEncoder(FlaskJSONEncoder):
include_nulls = False
def default(self, o):
if isinstance(o, Model):
dikt = {}
for attr, _ in six.iteritems(o.swagger_types):
value = getattr(o, attr)
if value is None and not self.include_nulls:
continue
attr = o.attribute_map[attr]
dikt[attr] = value
return dikt
return FlaskJSONEncoder.default(self, o)