Search code examples
flaskmarshallingflask-restplus

how to serialize JSONB field with marshall in flask restplus?


having model sqlalchemy like this

class Action(base):
    id = Column(Integer, primary_key=True)
    parameters = Column(JSONB)

how can I define serialization of parameters using flask restplus api.Model marshall?


Solution

  • I managed by using fields.Raw

    action_serializer = api.model('Action', {
        'id': fields.Integer,
        'parameters': fields.Raw
    })
    

    moreover, you can even reach for nested attr like this:

    'name': fields.String(attribute='parameters.name')