You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by jw...@apache.org on 2015/12/12 00:08:01 UTC

[3/3] groovy git commit: GROOVY-7707 - StreamingJsonBuilder - writing unescaped output doesn't reset state (closes #210)

GROOVY-7707 - StreamingJsonBuilder - writing unescaped output doesn't reset state (closes #210)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/7f72540d
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/7f72540d
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/7f72540d

Branch: refs/heads/master
Commit: 7f72540d4b4113818a53c41363b3839b3b36aa04
Parents: deb8395
Author: graemerocher <gr...@gmail.com>
Authored: Thu Dec 10 14:46:12 2015 +0100
Committer: John Wagenleitner <jw...@apache.org>
Committed: Fri Dec 11 14:31:18 2015 -0800

----------------------------------------------------------------------
 .../main/java/groovy/json/StreamingJsonBuilder.java |  1 +
 .../groovy/json/StreamingJsonBuilderTest.groovy     | 16 +++++++++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/7f72540d/subprojects/groovy-json/src/main/java/groovy/json/StreamingJsonBuilder.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/StreamingJsonBuilder.java b/subprojects/groovy-json/src/main/java/groovy/json/StreamingJsonBuilder.java
index 6b260d4..05dbcdc 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/StreamingJsonBuilder.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/StreamingJsonBuilder.java
@@ -647,6 +647,7 @@ public class StreamingJsonBuilder extends GroovyObjectSupport {
          */
         public void call(String name, JsonOutput.JsonUnescaped json) throws IOException {
             writeName(name);
+            verifyValue();
             writer.write(json.toString());
         }
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/7f72540d/subprojects/groovy-json/src/test/groovy/groovy/json/StreamingJsonBuilderTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/test/groovy/groovy/json/StreamingJsonBuilderTest.groovy b/subprojects/groovy-json/src/test/groovy/groovy/json/StreamingJsonBuilderTest.groovy
index f37e8ee..41b8841 100644
--- a/subprojects/groovy-json/src/test/groovy/groovy/json/StreamingJsonBuilderTest.groovy
+++ b/subprojects/groovy-json/src/test/groovy/groovy/json/StreamingJsonBuilderTest.groovy
@@ -93,8 +93,22 @@ class StreamingJsonBuilderTest extends GroovyTestCase {
             new StreamingJsonBuilder(w).call {
                 a 1
                 b JsonOutput.unescaped('{"name":"Fred"}')
+                c 3
             }
-            assert w.toString() == '{"a":1,"b":{"name":"Fred"}}'
+            assert w.toString() == '{"a":1,"b":{"name":"Fred"},"c":3}'
+        }
+    }
+
+
+    @CompileStatic
+    void testUnescapedJsonCompileStatic() {
+        new StringWriter().with { w ->
+            new StreamingJsonBuilder(w).call {
+                call 'a', 1
+                call 'b', JsonOutput.unescaped('{"name":"Fred"}')
+                call 'c', 3
+            }
+            assert w.toString() == '{"a":1,"b":{"name":"Fred"},"c":3}'
         }
     }