dataclass-wizard
dataclass-wizard copied to clipboard
Nested objects are deserialized as dictionaries instead of actual object
- Dataclass Wizard version: 0.22.3
- Python version: Python 3.11.8
- Operating System: Ubuntu 20.04.6 LTS
Description
You should be able to reproduce problem with A (More) Complete Example. This leads to problems when you start working with deserialized result but instead of expected objects there are dicts.
Expected
…
c = MyTestClass.from_dict(data)
print(repr(c))
# prints the following result on a single line:
# MyTestClass(
# my_ledger={'Day 1': 'some details', 'Day 17': ['a', 'sample', 'list']},
# the_answer_to_life=42,
# people=[
# Person(
# name=Name(first='Roberto', last='Fuirron', salutation='Mr.'),
# age=21, birthdate=datetime.datetime(1950, 2, 28, 17, 35, 20, tzinfo=datetime.timezone.utc),
# gender='M', occupation=['sailor', 'fisher'],
# hobbies=defaultdict(<class 'list'>, {'M-F': ['chess', '123', 'reading'], 'Sat-Sun': ['parasailing']})
# ),
# Person(
# name=Name(first='Janice', last='Darr', salutation='Dr.'),
# age=45, birthdate=datetime.datetime(1971, 11, 5, 5, 10, 59),
# gender='F', occupation='Dentist',
# hobbies=defaultdict(<class 'list'>, {})
# )
# ], is_enabled=True)
Actual
…
c = MyTestClass.from_dict(data)
print(repr(c))
# MyTestClass(
# my_ledger={'Day 1': 'some details', 'Day 17': ['a', 'sample', 'list']},
# the_answer_to_life=42,
# people=[
# {
# 'name': ('Roberto', 'Fuirron'),
# 'age': 21,
# 'birthdate': '1950-02-28T17:35:20Z',
# 'gender': 'M',
# 'occupation': ['sailor', 'fisher'],
# 'Hobbies': {'M-F': ('chess', 123, 'reading'), 'Sat-Sun': ['parasailing']}
# }, {
# 'name': ('Janice', 'Darr', 'Dr.'),
# 'age': 45,
# 'birthdate': '1971-11-05 05:10:59',
# 'gender': 'F',
# 'occupation': 'Dentist'
# }], is_enabled=True)