You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2014/07/25 09:53:53 UTC

svn commit: r1613360 - /sling/trunk/bundles/commons/json/src/main/java/org/apache/sling/commons/json/io/JSONRenderer.java

Author: bdelacretaz
Date: Fri Jul 25 07:53:52 2014
New Revision: 1613360

URL: http://svn.apache.org/r1613360
Log:
SLING-3776 - better indenting of child arrays

Modified:
    sling/trunk/bundles/commons/json/src/main/java/org/apache/sling/commons/json/io/JSONRenderer.java

Modified: sling/trunk/bundles/commons/json/src/main/java/org/apache/sling/commons/json/io/JSONRenderer.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/json/src/main/java/org/apache/sling/commons/json/io/JSONRenderer.java?rev=1613360&r1=1613359&r2=1613360&view=diff
==============================================================================
--- sling/trunk/bundles/commons/json/src/main/java/org/apache/sling/commons/json/io/JSONRenderer.java (original)
+++ sling/trunk/bundles/commons/json/src/main/java/org/apache/sling/commons/json/io/JSONRenderer.java Fri Jul 25 07:53:52 2014
@@ -55,6 +55,13 @@ public class JSONRenderer {
         private Options() {
         }
         
+        Options(Options opt) {
+            this.indent = opt.indent;
+            this.indentIsPositive = opt.indentIsPositive;
+            this.initialIndent = opt.initialIndent;
+            this.arraysForChildren = opt.arraysForChildren;
+        }
+        
         public Options withIndent(int n) {
             indent = n;
             indentIsPositive = indent > 0;
@@ -420,7 +427,7 @@ public class JSONRenderer {
             }
             if (sb.length() > 1) {
                 sb.append('\n');
-                indent(sb, opt.indent);
+                indent(sb, newindent);
             }
         }
         
@@ -431,8 +438,11 @@ public class JSONRenderer {
             } else {
                 sb.append('\n');
             }
+            final Options childOpt = new Options(opt);
+            childOpt.withInitialIndent(childOpt.initialIndent + newindent);
+            indent(sb, childOpt.initialIndent);
             sb.append(quote(opt.childrenKey)).append(":");
-            sb.append(prettyPrint(children, opt));
+            sb.append(prettyPrint(children, childOpt));
         }
         
         sb.append('}');