hi guys, I am experiencing a strange issue. I am u...
# serialization
c
hi guys, I am experiencing a strange issue. I am using serialization lib in order to parse a json string; it's a simple object with a list inside (
{data: [{..},{..}]}
); it works fine on android, while on iOS all the values inside the list are null. The external
data
object is parsed and the list too, but all the objects in the list have every value setted to null
the only thing that is a little bit "strange" is that all the properties inside the object are uppercased (
{"PROP":"value"}
). Could this be the issue?
Seems like it's not the issue. Maybe the issue is that I'm using a generic parameter for the list;
Copy code
@Serializable
data class BaseItemModelWrapper<T: BaseItemModel>(
  @SerialName("data") val data: List<T>
)
Ok probably figured out. Android can handle annotation on extended class, while iOS can't;
Copy code
class One {
  var a: String
}
@Serializable
class Two: One() {
  var b: String
}
on android parsing Two will parse both a and b while on iOS only b is parsed. The problem is that it's not possible to annotate both the base class and the specific one (leads to compile error)
Fixed. It is mandatory to override the var
Copy code
class One {
  var a: String
}
@Serializable
class Two: One() {
  override var a: String
  var b: String
}