diff options
author | Chris Seaton <chris.seaton@shopify.com> | 2020-10-07 03:13:48 +0100 |
---|---|---|
committer | Chris Seaton <chris.seaton@shopify.com> | 2020-10-07 17:28:13 +0100 |
commit | b8c1c640cd375f2e2ccca1b18bf943f80ad04816 (patch) | |
tree | fba7e360e7768522e7569a7c07bee4c72e6bfc50 /java | |
parent | 07c34048ff758c81be9d8b30f5d63084e5e9e072 (diff) | |
download | json-b8c1c640cd375f2e2ccca1b18bf943f80ad04816.tar.gz |
Fix an issue with generate_pretty and empty objects in the Ruby and Java implementations
Diffstat (limited to 'java')
-rw-r--r-- | java/src/json/ext/Generator.java | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/java/src/json/ext/Generator.java b/java/src/json/ext/Generator.java index 914d00e..fc17640 100644 --- a/java/src/json/ext/Generator.java +++ b/java/src/json/ext/Generator.java @@ -334,13 +334,13 @@ public final class Generator { buffer.append((byte)'{'); buffer.append(objectNl); - object.visitAll(new RubyHash.Visitor() { - private boolean firstPair = true; + final boolean[] firstPair = new boolean[]{true}; + object.visitAll(new RubyHash.Visitor() { @Override public void visit(IRubyObject key, IRubyObject value) { - if (firstPair) { - firstPair = false; + if (firstPair[0]) { + firstPair[0] = false; } else { buffer.append((byte)','); buffer.append(objectNl); @@ -360,7 +360,7 @@ public final class Generator { } }); state.decreaseDepth(); - if (objectNl.length() != 0) { + if (!firstPair[0] && objectNl.length() != 0) { buffer.append(objectNl); buffer.append(Utils.repeat(state.getIndent(), state.getDepth())); } |