Rui
09/29/2020, 2:37 PMcall.receive<Parameters>()
and got:
Unable to invoke no-args constructor for interface io.ktor.http.Parameters. Registering an InstanceCreator with Gson for this type may fix this problem
Any ideas?Dominik wuttke
09/29/2020, 3:58 PMinstall(ContentNegotiation) {
gson {
setDateFormat(DateFormat.LONG)
setPrettyPrinting()
register(ContentType.Text.Plain, GsonConverter(GsonBuilder().create()))
}
}
For received data with a ContentType of plain text, the received data will be converted with the GsonConverter. In my example I am calling
call.receive<FormMessage>()
at a later stage, FormMessage is a JSONObject from this class
data class FormMessage(val name: String, val email : String, val message: String)
Rustam Siniukov
09/29/2020, 4:23 PMGson
doesn’t know how to create Parameters
instance, because it is an interface. You can create class that will represent request body or use Map<String, Any>
Rui
09/29/2020, 6:04 PMRui
09/29/2020, 6:07 PMRustam Siniukov
09/30/2020, 7:58 AMreceive<Parameters>()
should work when your content type is multipart/form-data
or application/x-www-form-urlencoded