Adding comments to any elements in a JsonObject and outputting it with bareRootObject set to true will result in the indentation of the value getting messed up, while the indentation of the comment is correct.
For example, the following code:
JsonGrammar grammar = JsonGrammar.builder().bareRootObject(true).build();
JsonObject object = new JsonObject();
object.put("first_thing", new JsonPrimitive("First Thing"));
object.put("second_thing", new JsonPrimitive("Second Thing"), "This has a comment!");
object.put("third_thing", new JsonPrimitive("Third Thing"));
System.out.println(object.toJson(grammar));
Outputs the following string:
"first_thing": "First Thing",
// This has a comment!
"second_thing": "Second Thing",
"third_thing": "Third Thing"
While the output I would expect would be:
"first_thing": "First Thing",
// This has a comment!
"second_thing": "Second Thing",
"third_thing": "Third Thing"
Adding comments to any elements in a
JsonObject
and outputting it withbareRootObject
set totrue
will result in the indentation of the value getting messed up, while the indentation of the comment is correct.For example, the following code:
Outputs the following string:
While the output I would expect would be: