question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to transform request

See original GitHub issue

Content:

data class CreateAccountContent(
        val id: Int,
        val password: String
)

Main.kt:

fun main(args: Array<String>){
    val handler = DatabaseHandler()
    val server = embeddedServer(Netty, port = 12345) {
        routing {
            // ...
            post("/account"){
                try {
                    val post = call.receive<CreateAccountContent>()
                    if (handler.createUser(post)) {
                        call.respond(HttpStatusCode.OK, "OK")
                    } else {
                        call.respond(HttpStatusCode.BadRequest, "BAD")
                    }
                } catch (e: Exception) {
                    println(e)
                }
            }
        }
    }
    server.start(wait = true)
}

Curl request:

curl --request POST \
     --header "Content-Type: application/json" \
     --data '{"id": 7, "password": "ABCDEF"}' \
     http://localhost:12345/account

Output:

io.ktor.request.CannotTransformToTypeException: Cannot transform this request's content to class com.martmists.moneyservice.content.CreateAccountContent

Alternatively, I have tried the following Lua code:

http.post("http://localhost:12345/account",  -- url
          "id=7&password=ABCDEF")  -- POST Body

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
soywizcommented, Jul 11, 2018

You have to install the ContentNegotiation feature: https://ktor.io/features/content-negotiation.html

1reaction
theothermattmcommented, Mar 31, 2021

For anyone else who hits this, my issue was that I mistakenly installed ContentNegotiation inside the routing block and it should have been done outside it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Amazon APi gateway fails to generate transformed request
I was trying the integration of Amazon API gateway with Lambda function. I was successfully able to achieve though but when I tried...
Read more >
Unable to transform request to binary · Issue #4628
To implement binary support in api-gateway for file upload, i have used serverless-apigw-binary plugin and added necessary content types ...
Read more >
Lambda non-proxy integration errors out with "IntegrationError
Lambda non-proxy integration errors out with "IntegrationError: Execution failed due to configuration error: Unable to transform request".
Read more >
Resolve "Execution failed due to configuration" errors from ...
Why am I getting “Execution failed due to configuration” errors from API Gateway after using a CloudFormation template or OpenAPI definition ...
Read more >
Unable to get complete response when using api gateway
URL Path Parameters , URL Query String Parameters , HTTP Headers are empty . In Method Execution , Authorization , Request Validator are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found