I have a get request that returns certain features where 11 properties of the objects are common. Since data classes in Kotlin can't inherit from other classes i decided to define the common properties with the following interface.
interface AccountFeature {
val feature: String?
val status: String?
val id: String?
val urlLogo: String?
val minAppVersion: String?
val target: String?
val title: String?
val backgroundColor: String?
val bodyTextColor: String?
val bodyText: String?
val titleTextColor: String?
}
One of the data classes look like this.
data class AccountFeatureHelp(val privacyStatement: String? = null,
val supportFAQ: String? = null,
val termsOfService: String? = null,
val supportHotline: String? = null,
val supportEmail: String? = null,
override val feature: String?,
override val status: String?,
override val id: String?,
override val urlLogo: String?,
override val minAppVersion: String?,
override val target: String?,
override val title: String?,
override val backgroundColor: String?,
override val bodyTextColor: String?,
override val bodyText: String?,
override val titleTextColor: String?): AccountFeature
So far everthing is fine.
In the Interface definition of my Request, i expect an observable array of AccountFeature. My goal is depending on the feature value, mapping the hashmap to corresponding Feature object.
interface AccountFeaturesAPIService {
@GET("accounts/{id}/features")
fun getAccountFeature(@Path("id") id: String): Observable<Array<AccountFeature>>
}
I get the following runtime exception.
java.lang.RuntimeException: Unable to invoke no-args constructor for interface com.thinxnet.native_tanktaler_android.core.model.account.feature.AccountFeature. Registering an InstanceCreator with Gson for this type may fix this problem.
How would i overcome this in an elegant way apart from changing Observable> to Observable>