Closed ddorian closed 3 months ago
Maybe I'm misunderstanding your goal here, but marshmallow_field
can already be used to specify an explicit schema field for a particular dataclass field.
@dataclass
class Parent:
user: User = field(metadata={marshmallow_field=marshmallow.field.Nested(UserEventSchema)})
You're correct! Thank you!
I need to override the nested class. This is to use the same object in different presentations. A simple example would be we have a
User
class. And we want 2 presentations of it, one asUserDetails
(this is the User.Schema by default) on an API endpoint. The other as aUserEvent
, which has a different schema altogether.Is this approach ok? I can add tests etc.