Closed
Description
What is your use-case and why do you need this feature?
Output the enum and primitive correctly.
If we add a PrimitiveKind descriptor to a subclass of polymorphic serializer. There is error #1486
If we add a wrapper for the primitive(#1252 (comment)). The result will be wrapped even if the classDiscriminatorMode = ClassDiscriminatorMode.NONE
like below.
{
"data": {
"value": "FOO"
}
}
Describe the solution you'd like
https://github.com/Kotlin/kotlinx.serialization/blob/master/formats/json/commonMain/src/kotlinx/serialization/json/internal/Polymorphic.kt#L41
Avoid failing if needn't discriminator for checkKind
. Add a condition in checkKind
or encodePolymorphically
val kind = actual.descriptor.kind
if(needDiscriminator || (kind !is SerialKind.ENUM && kind !is PrimitiveKind)) checkKind(kind )