Ok, i made some progress by using ``` override ...
# serialization
m
Ok, i made some progress by using
Copy code
override val descriptor: SerialDescriptor = buildSerialDescriptor("Create", StructureKind.LIST) {
      element("target", serialDescriptor<String>())
      element("method", serialDescriptor<String>())
      element("properties", serialDescriptor<Map<String, Any>>())
    }
The remaining problem now is the Map<String, Any> part where i want to resolve the properties into a Map with properties and possible sublists. However there is not serializer for
Any
. Any advice on how to serialize the Any correctly within the properties map?
e
replace Any with JsonElement?
you could even let the entire properties be a JsonElement,.. then you could do:
Copy code
@Serializable data class Operation(val type: String, val active: Boolean, properties: JsonElement)
and skip doing custom serializer
m
Ah good call. 🙏
Changing the data class would be possibly but having regular kotlin types in there is preferred. Also, would't the serialization from the json array to the data class require the serializer anyway?
e
you’re right 🙂 sorry, thought that the example was just poorly formatted
m
@Emil Kantis Are you still around? I found that using
JsonElement
as the Map value type is actually not performing the correct conversion. It treats primitive values as
JsonPrimitive
, requiring to get the
content
to retrieve the actual value. Is there a way to have the
Any
be serialized and deserialized into kotlin types?
e
None that I can think of right now
m
That is what i thought. Thanks.