You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am currently struggling for best way to add property to existing jsonObject(kotlinx.serialization.json.JsonObject)
Even i have found that JsonObject internally has private immutable map
private val content: Map<String, JsonElement>
Scenario : Suppose i already have one jsonobject with 50 properties in it and considering jsonobject at any key can have any number of depth
For such situation how can we efficiently perform below operaions :
Adding primitive properties
Updating primitive properties
Deleting primitive properties
FYI : Even i have found there is class called JsonObjectBuilder but it do not take existing JsonElement / JsonObject / JsonArray infact it will newly create another jsonObject
I see stackoverflow already has correct answer: yeah, for bulk operation it's better to convert content to MutableMap first for better performance. For one-time operations, you can use standard collection extensions like + e.g. JsonObject(oldObject + ("foo" to JsonPrimitive(42)) (it creates a copy of the map)
I am currently struggling for best way to add property to existing jsonObject(kotlinx.serialization.json.JsonObject)
Even i have found that JsonObject internally has private immutable map
private val content: Map<String, JsonElement>
Scenario : Suppose i already have one jsonobject with 50 properties in it and considering jsonobject at any key can have any number of depth
For such situation how can we efficiently perform below operaions :
Adding primitive properties
Updating primitive properties
Deleting primitive properties
FYI : Even i have found there is class called JsonObjectBuilder but it do not take existing JsonElement / JsonObject / JsonArray infact it will newly create another jsonObject
Thanks for giving your time to read till here 😀
Stack Overflow Link
The text was updated successfully, but these errors were encountered: