Kotlin / kotlinx.serialization

Kotlin multiplatform / multi-format serialization
Apache License 2.0
5.43k stars 622 forks source link

JsonDecodingException with ignoreUnknownKeys #1606

Closed singhangadin closed 3 years ago

singhangadin commented 3 years ago

Describe the bug I am using KotlinxSerializer with Ktor in KMM Project. While doing so, I am getting JsonDecodingException (Stacktrace) for a key in JSON response I haven't added in the POJO. As mentioned in the docs I have set both isLenient and ignoreUnknownKeys flags, to resolve the issue but It doesn't seem to make any difference. You can check the snippet below to get an idea of how I am using the feature in my HttpClient

import kotlinx.serialization.json.Json as KotlinJson

install(JsonFeature) {
    serializer = KotlinxSerializer(
        KotlinJson {
            isLenient = true
            ignoreUnknownKeys = true
        }
    )
}

To Reproduce You can check the implementation in this repo: https://github.com/Angads25/KMM-Ktor-Features Although the code is not updated, the overall implementation hasn't changed.

Environment

Please feel free to ask for any other information not mentioned in the issue description.

sandwwraith commented 3 years ago

You're using a default instance instead of one you configured here: https://github.com/Angads25/KMM-Ktor-Features/blob/master/shared/src/commonMain/kotlin/com/github/angads25/kmmsampleapp/repository/NetworkUseCase.kt#L27