Test that @Transient private properties are ignored

Closes: https://github.com/square/moshi/issues/643
This commit is contained in:
Jesse Wilson 2018-09-09 15:34:58 -04:00
parent cb86194f8f
commit 1ba07d4b7d

View file

@ -925,6 +925,33 @@ class GeneratedAdaptersTest {
} }
} }
@Test fun privateTransientIsIgnored() {
val jsonAdapter = moshi.adapter(PrivateTransient::class.java)
val privateTransient = PrivateTransient()
privateTransient.writeA(1)
privateTransient.b = 2
assertThat(jsonAdapter.toJson(privateTransient)).isEqualTo("""{"b":2}""")
val fromJson = jsonAdapter.fromJson("""{"a":3,"b":4}""")!!
assertThat(fromJson.readA()).isEqualTo(-1)
assertThat(fromJson.b).isEqualTo(4)
}
@JsonClass(generateAdapter = true)
class PrivateTransient {
@Transient private var a: Int = -1
var b: Int = -1
fun readA(): Int {
return a
}
fun writeA(a: Int) {
this.a = a
}
}
@Test fun propertyIsNothing() { @Test fun propertyIsNothing() {
val moshi = Moshi.Builder() val moshi = Moshi.Builder()
.add(NothingAdapter()) .add(NothingAdapter())