In Java, we can add/remove property in JSONObject. In serialization, JsonObject is Map that can not be change. Is any suggestion to migrate this logic?
n
Nikky
08/20/2020, 8:53 AM
.toMutableMap()
You can create a new json object from a map
JsonObject(map)
Nikky
08/20/2020, 9:30 AM
I actually just append keys and create a new object from that
Nikky
08/23/2020, 6:15 AM
try
Copy code
fun JsonObject.put(key: String, value: Long): JsonObject {
return JsonObject(this + (key to JsonPrimitive(value)))
}
l
Luoqiaoyou
08/23/2020, 6:43 AM
but it seems have overhead, maybe i should give up extension function