Sean Proctor
01/29/2022, 3:02 PM@Serializable
data class FooInput {
val id: OptionalInput<@Serializable(with = UUIDSerializer::class) UUID> = OptionalInput.Undefined
}
How does the annotation in the type parameter work? It seems like it's discarded which causes the bug, but kotlinx.serialization looks a bit like magic to me.Dominaezzz
01/29/2022, 3:28 PMjava.lang.IllegalAccessException: class kotlin.reflect.jvm.internal.calls.CallerImpl$FieldGetter cannot access a member of class java.util.UUID (in module java.base) with modifiers "private final"
Dominaezzz
01/29/2022, 3:49 PMSean Proctor
01/29/2022, 4:05 PMDominaezzz
01/29/2022, 4:19 PMephemient
01/30/2022, 8:46 AMclass TypedOptionalInputSerializer<T : Any>(
private val delegate: KSerializer<T>
) : KSerializer<OptionalInput<T>> {
override val descriptor: SerialDescriptor = delegate.descriptor.nullable
override fun serialize(encoder: Encoder, value: OptionalInput<T>) {
encoder.encodeNullableSerializableValue(
delegate,
when (value) {
is OptionalInput.Undefined -> null
is OptionalInput.Defined -> value.value
}
)
}
override fun deserialize(decoder: Decoder): OptionalInput<T> =
OptionalInput.Defined(decoder.decodeNullableSerializableValue(delegate.nullable))
}
@Serializable
data class FooInput {
val id: @Serializable(with = TypedOptionalInputSerializer::class) OptionalInput<@Serializable(with = UUIDSerializer::class) UUID> = OptionalInput.Undefined
}
(untested but something along those lines)Sean Proctor
01/30/2022, 12:07 PM