Skip to content

Instantly share code, notes, and snippets.

@thenixan
Created January 30, 2018 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thenixan/991bc410c1ea7d5cb0272e8abda7c9b2 to your computer and use it in GitHub Desktop.
Save thenixan/991bc410c1ea7d5cb0272e8abda7c9b2 to your computer and use it in GitHub Desktop.
service.loadDataWithoutAnyParsingAtAll()
.flatMapObservable { responseBody ->
Observable.create<DataItem> { emitter ->
JsonReader(responseBody.charStream())
.use { reader ->
while (reader.hasNext()) {
if (reader.peek() == JsonToken.BEGIN_OBJECT) {
reader.beginObject()
if (reader.nextName() == "data") {
reader.beginArray()
while (reader.hasNext() && reader.peek() != JsonToken.END_ARRAY) {
emitter.onNext(Gson().fromJson<DataItem>(reader, DataItem::class.java))
}
}
}
}
emitter.onComplete()
}
}
}
.count()
.subscribe({ result ->
println("Size is: $result")
}, { error -> error.printStackTrace() })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment