-
Notifications
You must be signed in to change notification settings - Fork 5
Ambiguous serialization #27
Copy link
Copy link
Open
Description
It seems the union is ambiguous, ie it is not tagged...
As a result :
Python 3.7.5 (default, Nov 20 2019, 09:21:52)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.10.1 -- An enhanced Interactive Python. Type '?' for help.
PyDev console: using IPython 7.10.1
Python 3.7.5 (default, Nov 20 2019, 09:21:52)
[GCC 9.2.1 20191008] on linux
from marshmallow_union import Union
from marshmallow import fields
u = Union(fields=[fields.Integer(), fields.String()])u.serialize('v', {'v': 0})
# 0
u.serialize('v', {'v': '0'})
# 0
u.deserialize('0')
# 0
u.deserialize(0)
# 0
u.deserialize(u.serialize('v', {'v': '0'})) == u.deserialize(u.serialize('v', {'v': 0}))
# True
'0' == 0
# FalseFor reference, with pure marshmallow, serialization can be abused, but deserialization is always correct.
f = fields.Integer()
f.serialize('v', {'v': 0})
# 0
f.serialize('v', {'v': '0'})
# 0
f.deserialize(f.serialize('v', {'v': '0'})) == 0
# True
f.deserialize(f.serialize('v', {'v': 0})) == 0
# True
f.deserialize(f.serialize('v', {'v': '0'})) == '0'
# False
f.deserialize(f.serialize('v', {'v': 0})) == '0'
# False
f = fields.String()
f.deserialize(f.serialize('v', {'v': 0})) == '0'
# True
f.deserialize(f.serialize('v', {'v': 0})) == 0
# FalseThoughts ?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels