lidatong / dataclasses-json

Easily serialize Data Classes to and from JSON
MIT License
1.38k stars 154 forks source link

exclude is not propagated to marshmallow schema #369

Open andersk opened 2 years ago

andersk commented 2 years ago
from dataclasses import dataclass, field
from dataclasses_json import DataClassJsonMixin, Exclude, config

@dataclass
class MyClass(DataClassJsonMixin):
    my_field: int = field(metadata=config(exclude=Exclude.ALWAYS))

print(MyClass(0).to_dict())
# {}
print(MyClass.schema().dump(MyClass(0)))
# {'my_field': 0}

I expect {} for both outputs.

This was mentioned by @whisust in https://github.com/lidatong/dataclasses-json/issues/187#issuecomment-767815878 but deserves its own issue.

fawzi-kyndryl commented 2 years ago

facing the same issue. any update?

george-zubrienko commented 1 year ago

@andersk would you be willing to submit a PR to fix? :)

artificial-aidan commented 2 months ago

@george-zubrienko Took a stab at a PR for this