Hey I can't figure out how to serilize this in kotlin. Preferably with kotlinx serilizastion. Here a typescript reference. Can someone guide me to an implementation?
Copy code
function handleData(data: Record<string, unknown>) {
const bar: Record<string,unknown> = {
foo: "hi",
props: {...this.otherData, ...data}
}
return bar
}
This should end up as
Copy code
{
foo: "hi",
props: {
uno: 1
dos: "two"
}
}
j
Javier
01/04/2022, 12:10 AM
data class Some(val foo: String, val props: Map<String, Any>)
Javier
01/04/2022, 12:10 AM
or creating a sealed class for props so you can type safe it
Javier
01/04/2022, 12:10 AM
well... props is a list or just an object? in if it is just an object then
Javier
01/04/2022, 12:11 AM
data class Some(val foo: String, val props: Props)
data class Props(val uno: Int, val dos: String)
j
Jan
01/04/2022, 12:34 AM
props is an object which structure changes depending on the use case. Last time I tried to serialise
any
, kotlin complained but I am trying it tomorrow. Than you so much! @Javier
Jan
01/04/2022, 12:37 AM
I can implement it as list i guess
j
Javier
01/04/2022, 12:39 AM
sealed class should be valid if there is a limit of structures