Hey team! im working on a HTTP API and adding persistence using db: i merged the two sample project we have in the Ktor documentation: the customer api and this one https://ktor.io/docs/db-persistence.html... this is mas post routing:
Copy code
post {
val formParameters = call.receiveParameters()
val firstName = formParameters.getOrFail("firstName")
val lastName = formParameters.getOrFail("lastName")
val email = formParameters.getOrFail("email")
val customer = dao.addNewCustomer(firstName, lastName, email)
call.respond(mapOf("customer" to customer))
}
where
customer is the route (/customer)
: Im trying to add a new customer using curl command:
2024-04-22 162936.461 [eventLoopGroupProxy-4-3] DEBUG Application - Unhandled: POST - /customer. Exception class io.ktor.server.plugins.BadRequestException: Failed to convert request body to class io.ktor.http.Parameters
Caused by: io.ktor.serialization.JsonConvertException: Illegal input: Polymorphic serializer was not found for missing class discriminator ('null')
Im new on this backend stuff! any idea which coulb be the issue? and how can i add a new customer? the only way i found was doing an INSERT in the database
c
Chrimaeon
04/22/2024, 7:45 PM
You should look up the difference between „form parameters“ that you backend expects and a „json body“ that you actually send in the curl command via