Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 632
melchoir55 Avatar asked Apr 18 '19 19:04

melchoir55


1 Answers

You can use the Raw() field type.

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

like image 145
NJM Avatar answered Sep 21 '22 22:09

NJM