I am doing the following in Kotlin where desiredJsonStructure is a JSON structure that I define in the start of the class initialization
private lateinit var desiredJsonStructure: JSONObject
try {
val state = JSONObject()
state.put("xyz", JSONObject())
desiredJsonStructure = JSONObject()
desiredJsonStructure.put("abc", state)
} catch (e: JSONException) {
e.printStackTrace()
}
But when I assign the desiredJsonStructure object to another object and do changes in the finalDesiredState object, same changes are reflected in the desiredJsonStructure when I try to reuse it, means it than have the value that I have assign to finalDesiredState, looks like finalDesiredState is pointing to same memory as of desiredJsonStructure, how can I create a new finalDesiredState object with a new memory and assign the desiredJsonStructure value to finalDesiredState
val finalDesiredState: JSONObject = desiredJsonStructure