Alexandre Gressier
02/03/2025, 10:15 AMtypealias Tuple3<A, B, C> = @Serializable(with = CustomTuple3Serializer::class) Triple<A, B, C>
For context, I'm trying to use these serializers in a data class like the one below, so I even wonder if that’s feasible in the first place:
@Serializable
data class Value<T>(
val channel: Long,
val call: String,
val args: T, // Tuple types are used here (Pair, Triple…)
)
ephemient
02/03/2025, 4:51 PMtypeOf<Value<Triple<A, B, C>>>() == typeOf<Value<Tuple3<A, B, C>>>()
so the reified helper
Json.encodeToString(Value(0, "", Triple(a, b, c)))
does the same thing (with the default serializer) whether the value is Value<Triple<A, B, C>>
or Value<Tuple3<A, B, C>>
ephemient
02/03/2025, 4:54 PM@Serializable
data class Container(
val value: Value<Tuple3<String, String, String>>,
)
then the generated Container.serializer()
will use CustomTuple3Serializer
correctlyephemient
02/03/2025, 4:55 PMJson.encodeToString(
Value.serializer(CustomTuple3Serializer(serializer(), serializer(), serializer())),
Value(0, "", Triple(a, b, c)),
)
then it will use the one you specifiedAlexandre Gressier
02/04/2025, 4:32 PM