@dataclass
class MaybeBalls:
balls: Optional[List[str]]
class MaybeBallsSerializer(DataclassSerializer):
class Meta:
dataclass = MaybeBalls
input = {}
serializer = MaybeBallsSerializer(data=input)
print(serializer.data) # will fail
yields something like
File "/usr/local/lib/python3.8/site-packages/rest_framework/serializers.py", line 632, in data
ret = super().data
File "/usr/local/lib/python3.8/site-packages/rest_framework/serializers.py", line 320, in data
self._data = self.to_representation(self.validated_data)
File "/usr/local/lib/python3.8/site-packages/rest_framework/serializers.py", line 599, in to_representation
ret[field.field_name] = field.to_representation(attribute)
File "/usr/local/lib/python3.8/site-packages/rest_framework/fields.py", line 1692, in to_representation
return [self.child.to_representation(item) if item is not None else None for item in data]
TypeError: 'type' object is not iterable
adapted sample
yields something like
it tries to iterate over a