dataclasses-json icon indicating copy to clipboard operation
dataclasses-json copied to clipboard

Support usage of a custom encoder on nested dataclasses

Open whisust opened this issue 6 years ago • 1 comments

Currently, if we use a custom encoder on a nested dataclass, it is not called during serialization.

This pull request fixes it, with associated test cases.

As my use case was to strip None values at serialization, I was wondering if this was a common enough use case to add a boolean flag in the dataclass_json configuration to avoid writing a custom Encoder:

def dataclass_json(_cls=None, *, letter_case=None,
                   undefined: Optional[Union[str, Undefined]] = None,
                   skip_none: Optional[bool] = None):

If that's the case, I shall add this case to the config and see from there how to use the cls.dataclass_json_config at serialization time

whisust avatar Jan 06 '20 11:01 whisust

Hi @whisust, thanks for the contribution. Please update to match newest version on master and resolve conflicts, then we can proceed with a review

matt035343 avatar Aug 13 '23 09:08 matt035343