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

Setting default value when optional field's dependency is set

Open dodgyville opened this issue 3 years ago • 1 comments

Hi,

I love this library so much!

This is my snippet:

@dataclass_json
@dataclass
class Material():
    alphaMode: Optional[str]
    alphaCutoff: Optional[float] = 0.5

What I'm trying to do is only use the optional value of alphaCutoff if alphaMode is set. I'm recreating the dependencies rule from json schemas. Is there a way to specify this relationship?

dodgyville avatar Oct 22 '22 22:10 dodgyville

@matt035343 could this be an interesting brain teaser for you? :)

george-zubrienko avatar Jun 15 '23 06:06 george-zubrienko