Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Oct 7, 2020
1 parent 3926fed commit 61efee1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion java/src/json/ext/Generator.java
Expand Up @@ -334,6 +334,8 @@ void generate(final Session session, RubyHash object,

buffer.append((byte)'{');
buffer.append(objectNl);

final int[] count = new int[]{0};
object.visitAll(new RubyHash.Visitor() {
private boolean firstPair = true;

Expand All @@ -357,10 +359,11 @@ public void visit(IRubyObject key, IRubyObject value) {
Handler<IRubyObject> valueHandler = getHandlerFor(runtime, value);
valueHandler.generate(session, value, buffer);
session.infectBy(value);
count[0]++;
}
});
state.decreaseDepth();
if (objectNl.length() != 0) {
if (count[0] > 0 && objectNl.length() != 0) {
buffer.append(objectNl);
buffer.append(Utils.repeat(state.getIndent(), state.getDepth()));
}
Expand Down

0 comments on commit 61efee1

Please sign in to comment.