falkreon / Jankson

JSON5 / HJSON parser and preprocessor which preserves ordering and comments
MIT License
51 stars 9 forks source link

Adding comments with 'bareRootObject(true)' messes up indentation #44

Closed Olivki closed 3 years ago

Olivki commented 3 years ago

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"
falkreon commented 3 years ago

Fixed in staging. Thanks for the report! :)