Warning
Figuring out the correct field type from an untagged dump is a matter of guesswork and can be error-prone. A more explicit approach like https://github.com/Bachmann1234/marshmallow-polyfield/ is better. This project remains here to avoid breaking existing software.
marshmallow_union package¶
Module contents¶
Union fields for marshmallow.
- exception marshmallow_union.ExceptionGroup(msg, errors)[source]¶
Bases:
marshmallow_union.MarshmallowUnionException
Collection of possibly multiple exceptions.
- exception marshmallow_union.MarshmallowUnionException[source]¶
Bases:
Exception
Base exception for marshmallow_union.
- class marshmallow_union.Union(fields, reverse_serialize_candidates=False, **kwargs)[source]¶
Bases:
marshmallow.fields.Field
Field that accepts any one of multiple fields.
Each argument will be tried until one succeeds.
- Parameters
fields (
List
[Field
]) – The list of candidate fields to try.reverse_serialize_candidates (
bool
) – Whether to try the candidates in reverse order when serializing.