Is there a reason you cannot clone a Couchbase JsonObject in the Java SDK? If not, would that be able to be added in a future release?
In general we favor using copy constructors over cloning.
I’ll admit it’s a bit cumbersome to type, but does this satisfy your requirements?
JsonObject copy = JsonObject.from(original.toMap());
Our codebase uses the toString method with JsonObject.fromJson . Is there an advantage to doing it with the map instead?
Both give the same result. Using
toMap() performs better, since it doesn’t have to serialize and parse the JSON string.