You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't know if it is an expected result but here is something that didn't work and how to solve it.
I spent a lot of time to fix that.
Did the same with ktor-gson or ktor-jackson.
Ktor Version
1.0.1
Ktor Engine Used(client or server and name)
ktor-server-netty
JVM Version, Operating System and Relevant Context
jdk1.8.0_17 on macOS Mojave 10.14.1
Feedback
I'm getting
io.ktor.features.UnsupportedMediaTypeException: Content type application/json is not supported
at io.ktor.features.ContentNegotiation$Feature$install$3.invokeSuspend(ContentNegotiation.kt:100)
at io.ktor.features.ContentNegotiation$Feature$install$3.invoke(ContentNegotiation.kt)
at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:248)
at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(PipelineContext.kt:63)
at io.ktor.util.pipeline.SuspendFunctionGun.proceed(PipelineContext.kt:111)
at io.ktor.util.pipeline.SuspendFunctionGun.execute(PipelineContext.kt:131)
at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:24)
at io.ktor.request.ApplicationReceiveFunctionsKt.receive(ApplicationReceiveFunctions.kt:68)
at something.SomethingKt.notes(something.kt:176)
at something.SomethingKt$api$1.invokeSuspend(something.kt:8)
at something.SomethingKt$api$1.invoke(something.kt)
at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:248)
at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(PipelineContext.kt:63)
at io.ktor.util.pipeline.SuspendFunctionGun.proceed(PipelineContext.kt:111)
at io.ktor.util.pipeline.SuspendFunctionGun.execute(PipelineContext.kt:131)
at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:24)
at io.ktor.routing.Routing.executeResult(Routing.kt:148)
at io.ktor.routing.Routing.interceptor(Routing.kt:29)
at io.ktor.routing.Routing$Feature$install$1.invokeSuspend(Routing.kt:93)
at io.ktor.routing.Routing$Feature$install$1.invoke(Routing.kt)
at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:248)
at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(PipelineContext.kt:63)
at io.ktor.util.pipeline.SuspendFunctionGun.proceed(PipelineContext.kt:111)
at io.ktor.features.ContentNegotiation$Feature$install$1.invokeSuspend(ContentNegotiation.kt:60)
at io.ktor.features.ContentNegotiation$Feature$install$1.invoke(ContentNegotiation.kt)
at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:248)
at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(PipelineContext.kt:63)
at io.ktor.util.pipeline.SuspendFunctionGun.proceed(PipelineContext.kt:111)
at io.ktor.features.CallLogging$Feature$install$2.invokeSuspend(CallLogging.kt:124)
at io.ktor.features.CallLogging$Feature$install$2.invoke(CallLogging.kt)
at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:248)
at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(PipelineContext.kt:63)
at io.ktor.util.pipeline.SuspendFunctionGun.proceed(PipelineContext.kt:111)
at io.ktor.util.pipeline.SuspendFunctionGun.execute(PipelineContext.kt:131)
at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:24)
at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$2.invokeSuspend(DefaultEnginePipeline.kt:80)
at io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$2.invoke(DefaultEnginePipeline.kt)
at io.ktor.util.pipeline.SuspendFunctionGun.loop(PipelineContext.kt:248)
at io.ktor.util.pipeline.SuspendFunctionGun.access$loop(PipelineContext.kt:63)
at io.ktor.util.pipeline.SuspendFunctionGun.proceed(PipelineContext.kt:111)
at io.ktor.util.pipeline.SuspendFunctionGun.execute(PipelineContext.kt:131)
at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:24)
at io.ktor.server.netty.NettyApplicationCallHandler$handleRequest$1.invokeSuspend(NettyApplicationCallHandler.kt:31)
at io.ktor.server.netty.NettyApplicationCallHandler$handleRequest$1.invoke(NettyApplicationCallHandler.kt)
This code will throw:
fun Application.config() {
install(ContentNegotiation) {
gson {
serializeNulls()
}
}
// ...
}
fun Application.routes() {
routing {
post("/something") {
data classFoo(varbar:Int)
data classBar(varfoo:Int)
val foo = call.receive<Foo>()
val bar =Bar(foo.bar)
call.respond(bar)
}
// ...
}
}
This code will works:
data classFoo(varbar:Int)
data classBar(varfoo:Int)
fun Application.config() {
install(ContentNegotiation) {
gson {
serializeNulls()
}
}
// ...
}
fun Application.routes() {
routing {
post("/something") {
val foo = call.receive<Foo>()
val bar =Bar(foo.bar)
call.respond(bar)
}
// ...
}
}
The text was updated successfully, but these errors were encountered:
scorsi
changed the title
Got "Content type application/json is not supported" exception when the class to serialize is in the function
Got "Content type application/json is not supported" exception when the class to serialize/unserialize is in the function
Dec 20, 2018
GSON does never deserialize local and anonymous classes thus returns null. Unfortunately ktor doesn't support null deserialization for now so it simply throws UnsupportedMediaTypeException that is confusing.
Hello,
I don't know if it is an expected result but here is something that didn't work and how to solve it.
I spent a lot of time to fix that.
Did the same with
ktor-gson
orktor-jackson
.Ktor Version
1.0.1
Ktor Engine Used(client or server and name)
ktor-server-netty
JVM Version, Operating System and Relevant Context
jdk1.8.0_17
onmacOS Mojave 10.14.1
Feedback
I'm getting
This code will throw:
This code will works:
The text was updated successfully, but these errors were encountered: