genomoncology / related

Nested Object Models in Python with dictionary, YAML, and JSON transformation support
MIT License
198 stars 15 forks source link

Ignoring metadata field "key" when serializing or deserializing #46

Open RodrigoDeRosa-zz opened 3 years ago

RodrigoDeRosa-zz commented 3 years ago

It would be nice to be able to ignore the key metadata field when serializing or deserializing. An example would be:

class C:
    a_name = StringField(key='name')

json = {'name': 'Rodrigo'}
c = to_model(C, json)
d = to_dict(c, ignore_keys=True)

"""
d is {'a_name': 'Rodrigo'}
"""

It would also work

json = {'a_name': 'Rodrigo'}
c = to_model(C, json, ignore_keys=True)

I'll create a PR with my solution to this. I hope you find it useful as well and accept it :).