Skip to content

adamboche/python-marshmallow-union

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

docs Documentation Status
tests
Travis-CI Build Status AppVeyor Build Status
Coverage Status
package

Union fields for marshmallow.

  • Free software: MIT license

Warning

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')) # -> int

If you want to have precise control of which field will be used for which value, you can use marshmallow-polyfield instead of this library.

Documentation

https://python-marshmallow-union.readthedocs.io/