Skip to content

Prevent kotlinx.serialization usage on collection of interfaces #26371

@sdeleuze

Description

@sdeleuze

As a refinement of #26298, we should disable out of the box open polymorphic serialization for collections using something like:

// Pseudocode, not tested
fun hasPolymorphism(serializer: KSerializer<*>): Boolean = hasPolymorphism(serializer.descriptor)
fun hasPolymorphism(descriptor: SerialDescriptor): Boolean {
    if (descriptor.kind == PolymorphicKind.OPEN.INSTANCE) return true
    for (i in 0 until descriptor.elementsCount) {
        // TODO circuit breaker for recursive types
        if (hasPolymorphism(descriptor.getElementDescriptor(i)) return true
    }
   return false
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions