clarkduvall / serpy

ridiculously fast object serialization
http://serpy.readthedocs.org/en/latest/
MIT License
960 stars 62 forks source link

Return None if required=False #67

Closed digitaldavenyc closed 3 years ago

digitaldavenyc commented 6 years ago

I have a suggestion for how optional fields are returned when they are not included to a DictSerializer.

serpy 0.3.1 required=True required=False
data = {'value': 1} {'value': 1} {'value': 1}
data = {'value': None} {'value': None} {'value': None}
data = {} KeyError(u"Got KeyError when.... {}
Suggested required=True required=False
data = {'value': 1} {'value': 1} {'value': 1}
data = {'value': None} {'value': None} {'value': None}
data = {} KeyError(u"Got KeyError when.... {'value': None}

To me this makes more sense then excluding them from the dictionary serializers. Another option could also be to include a default property to fields. I think there should be "some" option for this regardless of the implementation.