Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Validate known fields and keep unknown fields? #747
Hi, I have a use case where I have a defined schema with some fields that need to be validated, and other fields that are "unknown" (a json document of this type has over 700 fields in various nesting levels) and does not need validation but need to be serialized and deserialized. Is this something that is possible with marshmallow? I could not find an answer for this specific use case in the docs. I saw #127 but this is not quite what I need. I need to validate everything defined in the schema and let it pass anything that is not defined.
Closing as duplicate of #718.
If the feature described in there was added, this could be achieved by adding
class Meta: additional_properties = fields.Raw()
In the meantime, you should be able to achieve this with a post_load method: it receives both
Please react if I'm wrong and I can reopen.
It is now possible to keep unknown fields in 3.0.0b12.
See #853 for a proposal to specify an output field for unknown fields.
This is good to see. Looking at the docs, it's unclear to me how the unknown fields are stored and how they can be used.
For example, if we're using this option, and I deser an entity that has unknown fields, if I serialize the same instance again, are those unknown fields inserted into the stream automatically?