docs | |
---|---|
tests | |
package |
Union fields for marshmallow.
- Free software: MIT license
This library works by trying a list of fields one by one, and (de)serializing with the first one not to raise an error. The type of the values is not taken into account, so if one of the fields in the union accepts values of an unexpected type, they will be used for serialization. This can lead to a surprising behavior, because :
u = Union(fields=[fields.Integer(), fields.String()]) # the Integer field accepts string representations of integers type(u.deserialize('0')) # -> intIf you want to have precise control of which field will be used for which value, you can use marshmallow-polyfield instead of this library.