bod
03/25/2023, 3:25 PMEvent
and am using @JsonClassDiscriminator
successfully for its subtypes. But now I have one of the subtypes (Message
) that should itself be a sealed class with a few sub-subtypes:
┌─────┐
│Event│ discriminator: "type"
└──▲──┘
┌─────┐ │ ┌───────┐
│React├────┴───┤Message│ discriminator: "subtype"
└─────┘ └───▲───┘
┌───┐ │ ┌────┐
│Add├────┴────┤Edit│
└───┘ └────┘
Naturally I'd put another @JsonClassDiscriminator
on Message
but that's not allowed.
Any tip on how I should handle this?Dominaezzz
03/26/2023, 11:44 AMbod
03/26/2023, 11:45 AMIt is not possible to define different class discriminators for different parts of class hierarchy.and if you actually try it in the IDE it will be red 🙂
Dominaezzz
03/26/2023, 11:48 AMbod
03/26/2023, 11:49 AMbod
03/26/2023, 11:49 AMDominaezzz
03/26/2023, 11:52 AMMessage
a concrete class then, then have a polymorphic member.bod
03/26/2023, 11:54 AMDominaezzz
03/26/2023, 11:58 AMval event: Event = Add()
Since there isn't a way to figure out the Message
class in between.Dominaezzz
03/26/2023, 12:00 PMbod
03/26/2023, 12:03 PMYou could consider using a single discriminator for the whole hierarchy.Do you mean a change in the backend? (it's out of my hands, this is actually for the Slack API)
Dominaezzz
03/26/2023, 12:06 PMbod
03/26/2023, 12:08 PM