You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's say I register a custom encoder/decoder for type T in the global_config. I would expect that a dataclass with a field of type Optional[T] to use the encoder/decoder registered. Instead I have to manually register the same encoder for the type Optional[T] for the encoder to be picked up. _user_overrides_or_exts does not unwrap the optional type.
Code snippet that reproduces the issue
from dataclasses import dataclass
from dataclasses_json import dataclass_json, global_config
from datetime import date
from typing import Optional
global_config.encoders[date] = date.isoformat
# global_config.encoders[Optional[date]] = date.isoformat
@dataclass_json
@dataclass
class DataClassWithIsoDatetime:
created_at: Optional[date] = None
print(DataClassWithIsoDatetime(date.today()).to_json())
Describe the results you expected
{"created_at": "2023-08-08"}
Python version you are using
3.9
Environment description
dataclasses-json==0.5.14
The text was updated successfully, but these errors were encountered:
This is becoming a bigger problem for me (global configs are also not applied from collections or mappings) so I will try to see if I can fix this tomorrow. It should be relatively simple.
Description
Let's say I register a custom encoder/decoder for type
T
in theglobal_config
. I would expect that adataclass
with a field of typeOptional[T]
to use the encoder/decoder registered. Instead I have to manually register the same encoder for the typeOptional[T]
for the encoder to be picked up._user_overrides_or_exts
does not unwrap the optional type.Code snippet that reproduces the issue
Describe the results you expected
{"created_at": "2023-08-08"}
Python version you are using
3.9
Environment description
dataclasses-json==0.5.14
The text was updated successfully, but these errors were encountered: