oxan / djangorestframework-dataclasses

Dataclasses serializer for Django REST framework
BSD 3-Clause "New" or "Revised" License
431 stars 28 forks source link

[Question]: Nested serializer with Union #54

Closed felippemr closed 2 years ago

felippemr commented 2 years ago

👋 I have a dataclass that look like this:

@dc
class Document:
    id: UUID
    details: Union[ComplianceDoc, SignatureDoc]
    ...

@dc
class ComplianceDoc:
    ...

@dc
class SignatureDoc:
    ...

What is the expected behavior if I give this to a serializer? Currently it is just getting the first type within the Union.

oxan commented 2 years ago

From the README:

Type unions are not supported yet.

Expected behavior is that you don't do that ;-)

I'm honestly not sure how type unions should work, though, particularly for deserialization. How should it know which type to expect?

oxan commented 2 years ago

Closing as not an actionable issue.