question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Polymorphic SerializersModule with generic class "Star projections in type arguments are not allowed"

See original GitHub issue

Consider this code:

val responseModule = SerializersModule {
    polymorphic(Response::class) {
        subclass(OkResponse::class)
    }
}

@Serializable
abstract class Response<out T>
            
@Serializable
class OkResponse<out T>(val data: T) : Response<T>()

Running it produces:

Caused by: java.lang.IllegalArgumentException: Star projections in type arguments are not allowed, but had example.examplePoly17.OkResponse<*> (Kotlin reflection is not available)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:25
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
Whathecodecommented, May 5, 2021

Not sure this is related, but I had the same error.

I found the following workaround: in my case, there was an interface constraint on the generic, and I could register the subclass as follows causing the error to disappear:

subclass(
    OkResponse::class,
    OkResponse.serializer( PolymorphicSerializer( InterfaceConstraint::class ) )
        as KSerializer<OkResponse<*>>
)
2reactions
sandwwraithcommented, Jul 19, 2022

Nope

Read more comments on GitHub >

github_iconTop Results From Across the Web

Polymorphic SerializersModule with generic class "Star projections ...
Polymorphic SerializersModule with generic class "Star projections in type arguments are not allowed"
Read more >
kotlin - error: Star projections in type arguments are not allowed
I want to deserialize JSON into a data class, Message , that has a field with a generic type. import kotlinx.serialization.SerialName import ...
Read more >
Generics and Polymorphism - Whizlabs Blog
The polymorphism applies only to the 'base' type (type of the collection class) and NOT to the generics type. Generic Methods. To understand...
Read more >
[client/server] Support polymorphic serializers : KTOR-1514
The following does not work because the type is generic and polymorphic. ... Star projections in type arguments are not allowed, ...
Read more >
Serializable - Kotlin
The main entry point to the serialization process. · For classes with generic type parameters, · In order to generate serializer function that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found