You are currently viewing How to serialize an array of different types of value with `kotlinx.serialization`.

How to serialize an array of different types of value with `kotlinx.serialization`.

I try the following code.

“` kotlin

import kotlinx.serialization.json.Json

Json.encodeToString(arrayOf(“gid”, arrayOf(“status”, “c”, “d”), 3))

“`

It gives the error message.

“`

Exception in thread “main” kotlinx.serialization.SerializationException: Class ‘String’ is not registered for polymorphic serialization in the scope of ‘Serializable’.

Mark the base class as ‘sealed’ or register the serializer explicitly.

“`

submitted by /u/Jason5Lee
[link] [comments]