Hi all. I'm getting ```kotlinx.serialization.json....
# serialization
x
Hi all. I'm getting
Copy code
kotlinx.serialization.json.internal.JsonEncodingException: Value of type 'kotlinx.serialization.Polymorphic<IdType>' can't be used in JSON as a key in the map. It should have either primitive or enum kind, but its kind is 'OPEN'.
where
Copy code
interface IdType : Parcelable {
  val name: String
}

enum class PersonIdType : IdType {
  GIVEN_NAME, MIDDLE_NAMES, FAMILY_NAME
}

enum class VehicleIdType : IdType {
  PLATE_NUMBER, VIN, ENGINE_NUMBER,
}
is this a known limitation? 🤔
d
You're asking for too much there. When you serialise an
IdType
the result is going to be an object and not a string. JSON doesn't allow object keys.
You'll need to write a custom serialiser for
IdType
to achieve what you want.
x
yeah makes sense. With a custom serialiser that serialise the idType to a string, it works as expected 👍