I convert the JsonObject to String, then parsed them back.
public static JsonObject clone(JsonObject o) {
if (o == null)
return null;
StringWriter buffer = new StringWriter();
JsonWriter writer = Json.createWriter(buffer);
writer.write(o);
writer.close();
return Json.createReader(new StringReader(buffer.toString())).readObject();
}
I look for more elegant method.
There is no point cloning JsonObject
. The javadoc states
JsonObject
class represents an immutable JSON object value (an unordered collection of zero or more name/value pairs).
Emphasis mine. Just re-use the object. No one will be able to change it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With