反序列化时的 Marshmallow 字段查找
是否可以使用 marshmallow
架构执行输入数据查找?以下不起作用..:
class ParentSchema(Schema):
child_name = fields.String(data_key="child.fname")
然后在反序列化期间:
data = {"child": {"fname": "John", "lname": "Doe"}}
ParentSchema().load(data)
结果是{}
。
marshmallow-v3.14.1
Is it possible to perform input data lookups with marshmallow
schemas ? The following does not work.. :
class ParentSchema(Schema):
child_name = fields.String(data_key="child.fname")
Then during deserialisation:
data = {"child": {"fname": "John", "lname": "Doe"}}
ParentSchema().load(data)
The result is {}
.
marshmallow-v3.14.1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
fields.Function
来实现此目的:结果为
{'child_name': 'John'}
。You can achieve this using
fields.Function
:And the result is
{'child_name': 'John'}
.