hi, I want to serialize a custom class into a nested map (with my own encoder, not introducing JSON ...
y
hi, I want to serialize a custom class into a nested map (with my own encoder, not introducing JSON into my code base). For example, if I have my data classes defined like this:
Copy code
@Serializable
data class Project(val name:String, val owners: List<Users>)

@Serializable
data class Users(val name: String)
After serialization, I wish to get a nested map equals to:
Copy code
val map = mutableMapOf<String, Any>()
map.put("name", "project_name")
map.put("owners", listOf(mapOf("name" to "user1"), mapOf("name" to "user2"))
Could you please give me some hint how can I implement this
Encoder
please ( I do have a
Decoder
working BTW)? Should my Encoder extend the
AbstractEncoder()
or
TaggedEncoder()
? May I get some document for how to implement this? The official guide only contains an example for serializing to
List
, but does not show how to get the key values if I want to serialize to
Map
. Thank you very much.
239 Views