added test for internal property without backing field (#921) (#947)

This commit is contained in:
Burkhard Mittelbach
2019-10-05 22:51:48 +02:00
committed by Zac Sweers
parent f51de08caf
commit 666d87be65

View File

@@ -1114,6 +1114,27 @@ class GeneratedAdaptersTest {
assertThat(e).hasMessageContaining("Failed to find the generated JsonAdapter class") assertThat(e).hasMessageContaining("Failed to find the generated JsonAdapter class")
} }
} }
// https://github.com/square/moshi/issues/921
@Test fun internalPropertyWithoutBackingField() {
val adapter = moshi.adapter<InternalPropertyWithoutBackingField>()
val test = InternalPropertyWithoutBackingField()
assertThat(adapter.toJson(test)).isEqualTo("""{"bar":5}""")
assertThat(adapter.fromJson("""{"bar":6}""")!!.bar).isEqualTo(6)
}
@JsonClass(generateAdapter = true)
class InternalPropertyWithoutBackingField {
@Transient
private var foo: Int = 5
internal var bar
get() = foo
set(f) { foo = f}
}
} }
// Has to be outside to avoid Types seeing an owning class // Has to be outside to avoid Types seeing an owning class