https://kotlinlang.org logo
#ktor
Title
# ktor
g

Guilherme Delgado

04/21/2021, 8:20 PM
Hello, This is my configuration:
Copy code
//client
HttpClient(Apache) {
    install(JsonFeature) { serializer = KotlinxSerializer(Json { ignoreUnknownKeys = true }) }
}

//server
install(ContentNegotiation) {
        kotlinx.serialization.json.Json { ignoreUnknownKeys = true }
//        gson { setPrettyPrinting() }
    }
and this is a sample request:
Copy code
val response = client.get<List<Event>>("<http://localhost:8080>${application.locationToUrl(EventsApi())}") {
    body = ...
    contentType(ContentType.Application.Json)
}
and this is the output:
Copy code
invalid: 415 Unsupported Media Type. Text: ""
But if I uncomment
gson { setPrettyPrinting() }
it works… Shouldn’t
kotlinx.serialization.json.Json
be enough? 🤔
r

Rustam Siniukov

04/21/2021, 8:57 PM
can you please create a minimal example and file a bug in YT?
👍 1
g

Guilherme Delgado

04/22/2021, 3:27 PM
@Rustam Siniukov I’m also facing problems with
@SerialName
I don’t if its related, but the SS can parse it (when it communicates for instance with Google Api or any other service), but the web app can’t (it shows null) 🤔
found it…
Copy code
install(ContentNegotiation) {
    json(kotlinx.serialization.json.Json {
        ignoreUnknownKeys = true
        prettyPrint = true
    })
}
instead of:
Copy code
install(ContentNegotiation) {
        kotlinx.serialization.json.Json {ignoreUnknownKeys = true }
    }
👍 1
4 Views