Generic Serialization
See original GitHub issuektor Server, kotlinx serialization
This issue is a try to draw attention to fixes made with respect to 1879 and partially related to 1858
With the current approach, kotlinx serialization feature is not able to perform serialization of generic classes during the call.respond
.
Suppose you want to formalize responses in a way like this:
@Serializable
data class APIResponse<T>(
val result: T,
val success: Boolean = true,
val errorCode: Int?,
@Serializable(with = DateTimeSerializer::class)
val timestamp: DateTime
)
In that situation serializer of APIResponse
would have an argument, in order to implicitly declare nested serializer:
val serializer = APIResponse.serializer(ContentReview.serializer())
And by calling call.respond
you would receive Can't locate argument-less serializer for class APIResponse
, since with the current fixes module.getContextual(value::class)
returns null.
I guess this problem also can be generalized to the case of call.receive<Boxed<Int>>()
Please consider specifying serializer to use in call.respond
and call.receive
in some way other than module.getContextual(...)
. Unless you want to deal with all of the feature requests related to kotlinx serialization of course.
My suggestion is to add an option to call.respond
/call.receive
in order to specify the serializer for complex cases and use default serializer installed through install(ContentNegotiation)
as a default one.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:10
- Comments:5 (2 by maintainers)
Top GitHub Comments
Yes, this is the known limitation that will be eliminated in the future.
I got the similar problem today: https://stackoverflow.com/q/70207677/3466808, any one can help?