Is it possible to encode / decode any valid json objects in string format in a custom serializer. For example the code below but not let it serialize as json string but as any valid JSON with unknown structure?
object JsonObjectSerializer : KSerializer<JsonObject> {
override val descriptor = PrimitiveSerialDescriptor("JsonObject", PrimitiveKind.STRING)
override fun deserialize(decoder: Decoder): JsonObject =
JsonObject(decoder.decodeString())
override fun serialize(encoder: Encoder, value: JsonObject): Unit =
encoder.encodeString(value.encode())
}
Out would be something like..
{
"some": "data",
"jsonObject": "{\"this\": \"should not be a string\"}"
}
But wanted output would be..
{
"some": "data",
"jsonObject": {"this": "should not be a string"}
}