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
The class discriminator for the TypedException is the errorType which is in the parent object. The JSON body doesn't include the class discriminator in the nested object itself, making it harder to just use the generated serializers as is.
Describe the solution you'd like
(I did notice #686 and #471, and there's probably a better way to handle this entire situation with aJsonContentPolymorphicSerializer, although the type variable in JsonMessageWrapper might make things a bit more complex)
I'm currently working with obtaining a polymorphic deserializer for the TypedException based on the value of the errorType :
val deserializer:DeserializationStrategy<outTypedExceptionV1> = jsonInstance.serializersModule.getPolymorphic(TypedExceptionV1::class, response.errorType)!!val typedExceptionBody:TypedExceptionV1= jsonInstance.decodeFromJsonElement(deserializer, response.error!!)
For this method, all the sealed subclasses of TypedException had to be registered with the serializersModule. I am wondering if there is a way to obtain a deserializer for a sealed class from just providing a class discriminator value without needing to register them all in the module.
The text was updated successfully, but these errors were encountered:
inthewaves
changed the title
Deserializing a sealed class where the class discriminator is one level above
Obtaining a deserializer for a subclass of a sealed class from just the class discriminator value
Dec 22, 2021
What is your use-case and why do you need this feature?
I am working with a JSON protocol where some messages have the following structure:
The class discriminator for the
TypedException
is theerrorType
which is in the parent object. The JSON body doesn't include the class discriminator in the nested object itself, making it harder to just use the generated serializers as is.Describe the solution you'd like
(I did notice #686 and #471, and there's probably a better way to handle this entire situation with a
JsonContentPolymorphicSerializer
, although the type variable inJsonMessageWrapper
might make things a bit more complex)Currently, the class is structured like this:
I'm currently working with obtaining a polymorphic deserializer for the
TypedException
based on the value of theerrorType
:For this method, all the sealed subclasses of
TypedException
had to be registered with theserializersModule
. I am wondering if there is a way to obtain a deserializer for a sealed class from just providing a class discriminator value without needing to register them all in the module.The text was updated successfully, but these errors were encountered: