https://kotlinlang.org logo
Title
d

Darren Lambert

05/24/2021, 10:04 PM
Hi guys, i use kx.ser and i'm stuck with my post request, the terminal say to me :
2021-05-24 17:50:38.841 [eventLoopGroupProxy-4-1] ERROR ktor.application - Unhandled: POST - /Music/Add
io.ktor.features.CannotTransformContentToTypeException: Cannot transform this request's content to Musics
What i have do wrong in my code ? 🥲 (I have do many research and soluce but he doesn't work)
post("/Add") {
        val post = call.receive<Musics>()
        aMusicDAO.addMusic(post)
        call.respondText("OK OK",ContentType.Text.Plain)
}

@Serializable
data class Musics(
    val tag:Int? =null,
    @JsonInclude(value=JsonInclude.Include.NON_NULL)
    val title:String?="",
    val artist:String?="",
    val duration: String?="",
    val tagU:Int? =null
)

 override fun addMusic(music: Musics){
        transaction {
                Music.insert{
                    it[title]= music.title ?:""
                    it[artist]=music.artist?:""
                    it[duration]=music.duration?:""
                    it[tagU]=music.tagU?:0
                }
            }
    }
a

asad.awadia

05/24/2021, 11:11 PM
Looks like the call.receive line is failing - the request body cant be converted to a music object
Also you shouldn't have /add as your path - that is bad design - post /music is adding/creating
c

Crazygit

05/26/2021, 11:06 AM
It may be you don't Install ContentNegotiation In your App