Convert JsonReader to Kotlin (#1505)

* Rename .java to .kt

* Convert JsonReader to Kotlin

Made it sealed along the way like JsonWriter

Some of the properties had different docs for setting and getting, which dokka doesn't seem to have a nice way to differentiate. Went with a little marked up form but open to suggestions.

* Restore isLenient name to lenient

This plays nice for both java and kotlin consumers, as it's still isLenient to java consumers but not a source breaking change for kotlin

* Fix peek nullability and a kotlin source change

* Fix another nullability

* Use collection builders

* Ok this didn't work quite as I expected

* Update moshi/src/main/java/com/squareup/moshi/JsonReader.kt

Co-authored-by: Parth Padgaonkar <1294660+JvmName@users.noreply.github.com>

Co-authored-by: Parth Padgaonkar <1294660+JvmName@users.noreply.github.com>
This commit is contained in:
Zac Sweers
2022-01-17 02:52:02 -05:00
committed by GitHub
parent e6081dc90e
commit 47697c2601
5 changed files with 679 additions and 709 deletions

View File

@@ -191,7 +191,7 @@ public class PolymorphicJsonAdapterFactory<T> internal constructor(
override fun fromJson(reader: JsonReader): Any? {
val peeked = reader.peekJson()
peeked.setFailOnUnknown(false)
peeked.failOnUnknown = false
val labelIndex = peeked.use(::labelIndex)
return if (labelIndex == -1) {
fallbackJsonAdapter?.fromJson(reader)