The problem I have is that I receive a data model of a service in json format. This model can not be modified on the server side. The problem is that some fields of that model are not consistent.
I am using a data model in kotlin in the following way:
data class ResumenModel(
@SerializedName("fGestiones") val fGestiones: FechaGestionModel? = null,
@SerializedName("gestiones") val gestiones: List<GestionModel>? = null,
)
class GestionModel (
@SerializedName("ID") val ID: String? = "",
@SerializedName("noCtes") val noCtes: String? = "",
@SerializedName("detalles") val detalles: List<DetalleModel>? = null
)
The problem is with gestiones
in ResumenModel
. In some requests, gestiones
is an array of GestionModel
and in other requests, the service responds with a GestionModel
object. So when using Gson to create the object, you can not do it since you can not cast the object to arrayList or vice versa.
I know it is working well because when I ignore gestiones
in ResumenModel
, fGestiones
if it is filled correctly (and it is another data model but simple with primitive variables)