Hey all. I'm getting a `JsonDecodingException` (fr...
# ktor
s
Hey all. I'm getting a
JsonDecodingException
(from kotlinx.serialization) which I believe is being caused by the source string being cut off after decoding it to a String from a
ByteArray
with the util extension function on
ByteReadChannel
.
Copy code
Unexpected JSON token at offset 195068: EOF JSON input: .....text !","field":0.0,"te
This particular error can only be thrown if the current position when iterating over the source string is >= the last index of the string, and my JSON is not being fully parsed, so I am assuming that the String is being truncated somehow before parsing.
Copy code
...
.onSuccess { it: HttpResponse ->
    val receiveString = it.content.toByteArray().decodeToString()
    ...
    //later
    return json.decodeFromString(receiveString) //cast to my return type T
}
Does anyone have any insight as to why this might be happening? Am I receiving my
HttpResponse
content
incorrectly? Note: I'm not using the kotlinx
JsonFeature
, using it separately. My only idea right now is that it is failing to allocate the entire string due to OOM and this is just the first place exposing it, but I'm pretty sure this would fail with a different exception if that was the case.
decodeToString()
is experimental but it was working as intended until very recently. I upgraded to Ktor 1.5.3 recently, but can't confirm that the version upgrade is what triggered it as I can't repro it locally, just see it in a crash report. It happens very infrequently, like ~.001% of all requests.
r
Hi, Can you please create issue in YT with reproducer? Another thing is using
response.content
is discouraged, because it gives you raw data, that wasn’t processed by any features. If you want to get
ByteReadChannel
, please use
receive<ByteReadChannel>()
, or
receive<ByteArray>()
in your case