Hi everyone, I am trying to find a way to deserialize a json object using Marshmallow.
I have a schema that is like this
class CustomerDTO(BaseDTO):
first_name: str = fields.Str(required=True)
last_name: str = fields.Str(required=True)
address: AddressDTO = fields.Nested(AddressDTOSchema, required=True)
class CustomerDTOSchema(Schema, CustomerDTO)
pass
class AddressDTO(BaseDTO):
street_name_one: str = fields.Str(required=True)
street_name_two: str = fields.Str(required=False)
state: str = fields.Str(required=True)
zip: str = fields.Str(required=True)
class AddressDTOSchema(Schema, AddressDTO)
pass
def GetJson():
customer_dto_data = request.get_json()
customer_dto_schema = CustomerDTOSchema().load(customer_dto_data)
customer_dto = CustomerDTO(**customer_dto_schema)
print(customer_dto) # prints out the entire object in dictionary format
print(customer_dto.first_name) # works great
print(customer_dto.address.street_name_one) # I get -> AttriuteError: 'dict' object has no attribute 'street_name_one'
print(customer_dto.address) # prints out the values for address just fine.
Is there a way for me to help the object be deserialized correctly?