add `Serdes.ListSerde()` helper
aSemy opened this issue · comments
Because of type-erasure, the following will not work in Kotlin
Serdes.ListSerde(ArrayList::class, Serdes.String())
None of the following functions can be called with the arguments supplied.
<init>(Class<TypeVariable(L)!>!, Serde<TypeVariable(Inner)!>!) where Inner = TypeVariable(Inner), L = TypeVariable(L) for constructor ListSerde<Inner : Any!, L : (Mutable)List<Inner!>!>(listClass: Class<L!>!, serde: Serde<Inner!>!) defined in org.apache.kafka.common.serialization.Serdes.ListSerde
ListSerde(Class<TypeVariable(L)!>!, Serde<TypeVariable(Inner)!>!) where L = TypeVariable(L), Inner = TypeVariable(Inner) for fun <L : (Mutable)List<Inner!>!, Inner : Any!> ListSerde(listClass: Class<L!>!, innerSerde: Serde<Inner!>!): Serde<(Mutable)List<Inner!>!>! defined in org.apache.kafka.common.serialization.Serdes
A workaround is to cast Class<*>
to Class<ArrayList<Inner>>
fun <Inner> ListSerde(
valueSerde: Serde<Inner>,
): Serde<MutableList<Inner>> {
@Suppress("UNCHECKED_CAST")
val listClass = ArrayList::class.java as Class<ArrayList<Inner>>
return Serdes.ListSerde<ArrayList<Inner>, Inner>(
listClass,
valueSerde
)
}
Add this to kotka-streams.
Are there any other similar Serdes that could have similar helper functions?