Refuse kotlin classes in ClassJsonAdapter (#749)

* Refuse kotlin classes in ClassJsonAdapter

* Fail()

* Tweak message
This commit is contained in:
Zac Sweers
2018-11-19 23:36:52 -08:00
committed by GitHub
parent 4550da0abe
commit c64138bf0a
2 changed files with 20 additions and 0 deletions

View File

@@ -952,4 +952,16 @@ class KotlinJsonAdapterTest {
assertThat(adapter.fromJson("null")).isNull()
assertThat(adapter.toJson(null)).isEqualTo("null")
}
@Test fun kotlinClassesWithoutAdapterAreRefused() {
val moshi = Moshi.Builder().build()
try {
moshi.adapter<PlainKotlinClass>(PlainKotlinClass::class.java)
fail("Should not pass here")
} catch (e: IllegalArgumentException) {
assertThat(e).hasMessageContaining("Reflective serialization of Kotlin classes")
}
}
class PlainKotlinClass
}