You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a way to decode unexpected discriminator types? Right now, an exception is raised when an unknown discriminator value is provided. I'd like to be able to deserialize the unknown type into an object rather than handling the error.
Example config
objectSchema {
sealedtraitEvent {
defkind
}
caseclassCreateEvent() extendsEventcaseclassDeleteEvent() extendsEventcaseclassUnknownEvent(kind: String)
implicitvalcodec=JsonCodecMaker.make[Event](CodecMakerConfig
.withDiscriminatorFieldName(Some("kind"))
// Totally made up config method to show the desired behavior.// Not trying to suggest an exact implementation.
.withDiscriminatorFallback(UnknownEvent()))
}
Example usage
When an unexpected value is returned, return the configured unknown event class.
If I understand correctly your JSON input cannot be fully modeled by case classes or evolves faster than your model and the idea of your solution is to avoid throwing of an error for events that are not modeled yet.
Based on your code samples I wrote the possible solution here.
Is there a way to decode unexpected discriminator types? Right now, an exception is raised when an unknown discriminator value is provided. I'd like to be able to deserialize the unknown type into an object rather than handling the error.
Example config
Example usage
When an unexpected value is returned, return the configured unknown event class.
The text was updated successfully, but these errors were encountered: