Search code examples
pythonserializationmarshmallow

Marshmallow field of any type


I want to specify a marshmallow schema. For one of my fields, I don't want the schema to validate the type, but to simply pass it on. This is because the type could be anything, we don't know ahead of time. I don't see an option in marshmallow.fields for this. We want to use this as a deserializer.

For example

class FilterSchema(Schema):
        op = fields.Str(required=True)
        val = fields.**Any**(required=True)

Is there a way to do something like this?


Solution

  • You can use the Raw() field type.

    e.g. val = fields.Raw(required=True).