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
I want to be able to create nested objects in the definition of the primary object, such that I can pass in dictionaries that does not know about avro.
So from the tutorial:
from dataclasses import dataclass
import typing
from dataclasses_avroschema import AvroModel
@dataclass
class Address(AvroModel):
"An Address"
street: str
street_number: int
@dataclass
class User(AvroModel):
"User with multiple Address"
name: str
age: int
addresses: typing.List[Address]
data_user = {
"name": "john",
"age": 20,
"addresses": [ {
"street": "test",
"street_number": 10,
}],
}
user = User(**data_user)
assert type(user.addresses[0]) is Address
In order not to introduce backwards inconvertabilities an optional init argument or an alternative init could be introduced:
user = User(**data_user, nested=True)
assert type(user.addresses[0]) is Address
user = User.nested_init(**data_user)
assert type(user.addresses[0]) is Address
The text was updated successfully, but these errors were encountered:
I want to be able to create nested objects in the definition of the primary object, such that I can pass in dictionaries that does not know about avro.
So from the tutorial:
Inpiration for an implimentaion can be found on https://stackoverflow.com/questions/51564841/creating-nested-dataclass-objects-in-python/65326010
In order not to introduce backwards inconvertabilities an optional init argument or an alternative init could be introduced:
The text was updated successfully, but these errors were encountered: