I have a JsonArray which I am getting as a result of call to a method and it looks like - ["#group-apiTest2","#group-apiTest3","#group-apiTest4"]
I want to insert one more string - "group-apiTest1" in this JsonArray.
So far I tried this but got a different output then expected.
String group1 = "#group-apiTest1";
JsonArray existingArray = ["#group-apiTest2","#group-apiTest3","#group-apiTest4"] //For representation purpose only.
JsonObject jsonRequest = Json.createObjectBuilder().add("tags",
Json.createArrayBuilder().add(group1).add(existingArray))
.build();
logger.info("REQUEST - {}", jsonRequest);
The output of the logger is -
REQUEST - {"tags":["group-apiTest",["#group-apiTest2","#group-apiTest3","#group-apiTest4"]]}
instead of -
REQUEST - {"tags":["group-apiTest","#group-apiTest2","#group-apiTest3","#group-apiTest4"]}
Please let me know how to get the expected output. Where am I doing wrong? Thanks.