pyserde icon indicating copy to clipboard operation
pyserde copied to clipboard

field skips don't work with custom serializer?

Open AustinScola opened this issue 3 years ago • 1 comments

I think that skip_if_default, skip_if_false, and skip_if don't work if there is a custom serializer?

Example:

from serde import serde, field
from dataclasses import dataclass
from serde.json import to_json

@serde
@dataclass
class Foo:
    bar: str = field(
        default="bar",
        serializer=lambda x: "...",
        skip_if_default=True,
    )

print(to_json(Foo()))  # prints '{"bar":"..."}'

AustinScola avatar Jun 21 '22 17:06 AustinScola

It is actually intended behavior but I will double-check if this is possible 👍

yukinarit avatar Jul 05 '22 11:07 yukinarit