savrov
08/03/2020, 9:58 PM@Serializable
class SomeRequestBody(
@SerialName("name_field")
val name: String?
)
In KTOR Server, I have defined EP with such a request body. The problem is, that it works, if json looks like:
{
"name": "some-name-string"
}
but does not work if im trying to do the same with
{
"name_field": "some-name-string"
}
Do you know how to fix it?
P.S. Content negotiation is enabled in application module like
install(ContentNegotiation) {
gson {
setPrettyPrinting()
}
}
Thank you in advancejorge.rego
08/04/2020, 7:32 AMsavrov
08/04/2020, 7:34 AMdate_something
, but i dont want to use an underscore in source code.jorge.rego
08/04/2020, 7:47 AMinstall(ContentNegotiation) {
serialization()
}
savrov
08/04/2020, 1:39 PMgson
to kotlinx.serialization
then i should to write a custom serializer for my ApiResponse<T>. It looks a bit tricky, but will give a tryApiResponse<T>
with kotlinx.serialization
. So i’ve created a ApiResponseSerializer
class, with help of docs. But now i don’t understand how to use that serializer, since none of provided methods doesn’t seem to suit to me. That is the place where i need a help.
My ApiResponse<T> is defined like:
data class ApiResponse<T>(
val data: T? = null,
val error: ApiError? = null
)
And the regular usage (in KTOR) is
respond(
HttpStatusCode.Created,
ApiResponse(data = response.data)
)
I don’t know where i can “attach” my serializer to data
field of my ApiResponse
class.
Thank you in advance.jorge.rego
08/04/2020, 2:59 PMinstall(ContentNegotiation) {
gson {
// HERE YOU ARE CONFIGURING YOUR SERIALIZER
setPrettyPrinting()
}
}
savrov
08/04/2020, 3:04 PMjorge.rego
08/04/2020, 3:08 PMsavrov
08/04/2020, 3:09 PM