Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decodeFromBufferedSource throws JsonDecodingException on big JSON #2006

Artman12 opened this issue Aug 6, 2022 · 2 comments · Fixed by #2007

decodeFromBufferedSource throws JsonDecodingException on big JSON #2006

Artman12 opened this issue Aug 6, 2022 · 2 comments · Fixed by #2007


Copy link

Artman12 commented Aug 6, 2022

Describe the bug
Trying to use new Okio streams, introduced recently and encountering JsonDecodingException when trying to decode big JSON via decodeFromBufferedSource().

decodeFromString() works fine.

To Reproduce

data class Node(
    val children: List<Node>?

fun test() {
        fun getNodes(count: Int, depth: Int) : List<Node> {
            val ret = mutableListOf<Node>()
            if (depth == 0) return ret
            for (i in 0 until count) {
                ret.add(Node(getNodes(1, depth - 1)))
            return ret

        val rootNode = Node(getNodes(1000, 10))

        val json = Serializer.json.encodeToString(rootNode)

        val buffer = okio.Buffer().apply {

//        val decodedNode = Serializer.json.decodeFromString<Node>(json) // works fine
        val decodedNode = Serializer.json.decodeFromBufferedSource<Node>(buffer) // throws JsonDecodingException 

Exception error:

kotlinx.serialization.json.internal.JsonDecodingException: Expected colon ':', but had 'EOF' instead at path: $.children[107].children[0].children[108]
    JSON input: .....hildren":[{"children":[{"children":[{"children":[{"children"

I've created github repository with reproducible example:

Expected behavior
decodeFromBufferedSource decodes JSON correctly.


  • Kotlin version: 1.7.10
  • Library version: 1.4.0-RC
  • Kotlin platforms: JVM, Native
Copy link

ihostage commented Aug 18, 2022

Hm 🤔 GH didn't close this automatically when #2007 was merged.

Copy link

qwwdfsad commented Aug 18, 2022

It closes automatically only when it is merged to master. The PR was merged to dev branch, master contains only sources for the latest release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging a pull request may close this issue.

4 participants