https://kotlinlang.org logo
Title
z

zt

04/16/2023, 5:33 PM
I'm trying to use generics in a custom serializer like this
@Serializable
data class Tab<T>(
  @Serializable(ContentSerializer::class)
  val content: T? = null
) {
  private class ContentSerializer<T : Any>(tSerializer: KSerializer<T>) : JsonTransformingSerializer<T>(tSerializer) {
    override fun transformDeserialize(element: JsonElement) = element.jsonObject.values.last()
  }
}
But android studio show
Class 'ApiBrowse.Contents.BrowseResultsRenderer.Tab.ContentSerializer<*>', which is serializer for type 'Any', is applied here to type 'T?'. This may lead to errors or incorrect behavior.
And i get some cursed internal backend compilation error
k

kevin.cianfarini

04/16/2023, 5:37 PM
This is maybe silly, but should
ContentSerializer
apply to type
Any?
and not
Any
?
z

zt

04/16/2023, 5:53 PM
I don't think Any can be marked nullable
same error without nullable T