def encode(model: structures.Model):
try:
serialization_result = model.Meta.schema().dumps(model)
except AttributeError as e:
raise exceptions.EncodingError(e)
except marshmallow.ValidationError as e:
raise exceptions.EncodingError(e.messages)
else:
if serialization_result.errors:
raise exceptions.EncodingError(serialization_result.errors)
else:
return serialization_result.data
评论列表
文章目录