I have a String object containing some arbitrary json. I want to wrap it inside another json object, like this:
{
version: 1,
content: >>arbitrary_json_string_object<<
}
How can I reliably add my json string as an attribute to it without having to build it manually (ie avoiding tedious string concatenation)?
class Wrapper {
int version = 1;
}
gson.toJson(new Wrapper())
// Then what?
Note that the added json should not be escaped, but a be part of the wrapper as a valid json entity, like this:
{
version: 1,
content: ["the content", {name:"from the String"}, "object"]
}
given
String arbitraryJson = "[\"the content\", {name:\"from the String\"}, \"object\"]";