David Gethers
02/04/2020, 11:56 PMkotlinx.serialization
and the exception occurs with call.receive<MyMode>
. I’m curious if it a similar issue is the same as @nrobi. I don’t get the java.lang.NoClassDefFoundError
but I do get io.ktor.features.CannotTransformContentToTypeException: Cannot transform this request's content to
. I followed the instructions in https://ktor.io/servers/features/content-negotiation/serialization-converter.html and https://ktor.io/servers/calls/requests.html. I have the correct grade entry in my build.gradle file:
implementation "io.ktor:ktor-serialization:$ktor_version"
I install the ContentNegotiator:
fun Application.module() {
install(ContentNegotiation) {
serialization(
contentType = ContentType.Application.Json,
json = Json(DefaultJsonConfiguration.copy(prettyPrint = true))
)
}
val dao = DAOFacadeDatabase(Database.connect("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", driver = "org.h2.Driver"))
val server = embeddedServer(Netty, port = 8080) {
I have my simple data class:
data class UrlMap(val id: String, val url: String, val userId: String)
The exception is thrown here:
val receive = call.receive<UrlMap>()
I follow multiple examples on website and the official Ktor documentation and I can’t get it to work. I’m using Ktor 1.3.0 with Kotlin 1.3.61.
Any help would be greatly appreciatedTim Malseed
02/04/2020, 11:59 PMCannot transform this requestIt sounds like your request data doesn’t match what the content negotiator expects
Tim Malseed
02/04/2020, 11:59 PMDavid Gethers
02/05/2020, 3:08 AM{
"id": "7",
"url": "<https://kotlinlang.org/>",
"userId": "user1"
}
Data Class:
data class UrlMap(val id: String, val url: String, val userId: String)
Also I doublechecked the headers as well, making sure this was present:
Content-Type: application/json
nrobi
02/06/2020, 7:27 AMe5l
02/06/2020, 7:29 AMlouiscad
02/06/2020, 9:44 AM@Serializable
annotation?David Gethers
02/07/2020, 3:11 PM@Serializable
.nrobi
02/07/2020, 3:12 PMDavid Gethers
02/07/2020, 3:20 PMkotlinx.serialization compiler plugin is not applied to the module, so this annotation would not be processed. Make sure that you've setup your buildscript correctly and re-import project.
Let me see how I can get rid of this warning.David Gethers
02/07/2020, 3:20 PMnrobi
02/07/2020, 3:22 PMid("kotlinx-serialization")
plugin, let’s see if it helpsDavid Gethers
02/07/2020, 3:36 PMlouiscad
02/07/2020, 4:43 PMDavid Gethers
02/07/2020, 7:19 PMDavid Gethers
02/08/2020, 5:09 PMadding-url-mapping
louiscad
02/08/2020, 5:13 PMsandwwraith
02/10/2020, 9:36 AMnrobi
02/10/2020, 9:38 AMe5l
02/10/2020, 10:20 AMDavid Gethers
02/12/2020, 8:55 PMchristoph.pickl
02/16/2020, 11:28 AMEngineMain
and then the second time in the Application.module()
definition through calling embeddedServer()
.
after solving that, there was a simple transaction {}
missing in your DAO.
my patch attached here also contains the proper test (test first 🙌🏻 ).
hope that helps, all the best and enjoy ktor, christophDavid Gethers
02/18/2020, 4:49 PM