If I have an open class and inherited data class from it, Kotlin-moshi codegen skip default value. Is this intended behaviour? How to make moshi-kotlin parse all values including default from superclass?
@JsonClass(generateAdapter = true)
data class B(val bar: String) : A(foo = "foo")
@JsonClass(generateAdapter = true)
open class A(val foo: String)
val b = B("bar")
adapter.toJson(b)
prints {"bar":"bar"}
without channel field.
Make your superclass property mutable can solve your issue.
@JsonClass(generateAdapter = true)
data class B(val bar: String) : A(foo = "foo")
@JsonClass(generateAdapter = true)
open class A(var foo: String)
Output
{"bar":"bar","foo":"foo"}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With