-
Notifications
You must be signed in to change notification settings - Fork 620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for serializer<@Contextual T>
#2767
Comments
The |
@UnknownJoe796 As @xiaozhikang0916 says, you can just look up the serializer from the module. |
I'm not sure what you are trying to achieve here since a) the class Uuid
object UuidSerializer: KSerializer<Uuid> {
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("MyUuid", PrimitiveKind.STRING)
override fun serialize(encoder: Encoder, value: Uuid) {
TODO("Not yet implemented")
}
override fun deserialize(decoder: Decoder): Uuid {
TODO("Not yet implemented")
}
}
val myModule = SerializersModule {
contextual(Uuid::class, UuidSerializer)
}
inline fun <reified IN> postHandler(action: (IN) -> Unit) {
println(myModule.serializer<IN>().descriptor)
}
@Test
fun contextualDemo() {
postHandler<Uuid> { } // prints PrimitiveDescriptor(MyUuid)
} |
The following incomplete code cannot be used because
@Contextual
doesn't work inserializer<T>()
.This code would allow for very short definitions of server endpoints that handle serialization across multiple
Content-Type
s.Attempting to use this crashes because the
@Contextual
annotation isn't carried through.What I would expect is to get a
ContextualSerializer
for the type.The text was updated successfully, but these errors were encountered: