Hey team! im working on a HTTP API and adding pers...
# ktor
e
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:
curl -H "Content-Type: application/json" -d '{"firstName": "Raul", "lastName": "Garcia", "email": "<mailto:raulGar@mail.com|raulGar@mail.com>"}' <http://127.0.0.1:8080/customer>
and im having the issue
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')
JSON input: {"firstName":"Raul","lastName":"Garcia","email":"raulGar@mail.com"}
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
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
-d
e
Thanks @Chrimaeon, really helpful