GuilhE
GuilhE

Reputation: 11891

IllegalStateException("JsonReader is closed")

This code doesn't throw:

override fun fromJson(reader: JsonReader): List<MyObj> {
        val result = ArrayList<MyObj>()
        reader.beginObject()
        while (reader.hasNext()) {
            result.add(MyObj(reader.nextName(), reader.nextString()))
        }
        reader.endObject()
        return result
}

But if I add reader.close before return, or use reader.use { }, it will and it's catched here:

private fun <T> networkTransform(): SingleTransformer<Response<T>, Response<T>> {
        return SingleTransformer {
            it.onErrorResumeNext { throwable -> ...}
            ...

So my question is, do we need to handle close()?

Upvotes: 0

Views: 143

Answers (1)

Zac Sweers
Zac Sweers

Reputation: 3201

You shouldn't close a reader in a JsonAdapter itself, only the calling code (I.e. whoever created the reader and called fromJson()) needs to handle it.

Upvotes: 2

Related Questions