You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a base class which has private vals defined in its constructor. and a data class subclass which passes these values to the super constructor.
abstractclassMyAbstractClass(
@Transient privatevaltexts:Map<String, String>
@Transient privatevalimageUrls:Map<String, String>
) {
val title:String? get() = texts["title"]
val posterImage:String? get() = images["poster"]
}
@JsonClass(generateAdapter =true)
data classMyConcreteClass(
valtexts:Map<String, String>
) : MyAbstractClass(texts)
Right now it is then required to annotate all private properties of MyAbstractClass as @Transient because the codegen will otherwise throw an exception.
Since having all primary constructor properties being a val is a requirement of a data class I think the moshi codegen module should be able to figure out that the private property in the super class should never be (de)serialized and thus there is no need to crash when the property is private.
The text was updated successfully, but these errors were encountered:
We conferred. It’s a good proposal in isolation, but it brings up some potentially surprising consequences...
Lets start with this class:
open class BaseServerResponse(
var error_message: String?
)
Servers send the error_message field down sometimes when something breaks. Client developers are like “hey, why is this a val? nobody writes it!” and they flip it to a val.
open class BaseServerResponse(
val error_message: String?
)
With this change the system appears to work normally but now Moshi ignores this field! Bad!
I have a base class which has
private val
s defined in its constructor. and adata class
subclass which passes these values to the super constructor.Right now it is then required to annotate all private properties of
MyAbstractClass
as@Transient
because the codegen will otherwise throw an exception.Since having all primary constructor properties being a
val
is a requirement of a data class I think the moshi codegen module should be able to figure out that the private property in the super class should never be (de)serialized and thus there is no need to crash when the property is private.The text was updated successfully, but these errors were encountered: