You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 3, 2020. It is now read-only.
When writing a reader, one has to step through the JSON stream entry by entry. Value accessors like nextInt() fail if they encounter NULL; dealing with JSON elements that can, in Kotlin terms, be Int? is cumbersome.
The workaround is quite easy:
fun JsonReader.nextIntOrNull(): Int? {
if ( this.peek() !=JsonToken.NULL ) {
returnthis.nextInt()
} else {
this.nextNull()
returnnull
}
}
One could argue for this.peek() == JsonToken.NUMBER (where does the distinction between integers and floats happen, by the way?); that's a design decision between silent and loud parsing errors.
Please include nullable variants into JsonReader.
The text was updated successfully, but these errors were encountered:
When writing a reader, one has to step through the JSON stream entry by entry. Value accessors like
nextInt()
fail if they encounterNULL
; dealing with JSON elements that can, in Kotlin terms, beInt?
is cumbersome.The workaround is quite easy:
One could argue for
this.peek() == JsonToken.NUMBER
(where does the distinction between integers and floats happen, by the way?); that's a design decision between silent and loud parsing errors.Please include nullable variants into
JsonReader
.The text was updated successfully, but these errors were encountered: