groovy
  1. groovy
  2. GROOVY-4925

JsonBuilder with Writer support would be handy

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.0
    • Fix Version/s: 1.8.1, 1.9-beta-1
    • Component/s: groovy-jdk
    • Labels:
      None
    • Number of attachments :
      2

      Description

      JsonBuilder currently loads all of the data into an internal Map.

      It would be really nice to have a JsonBuilder which takes a Writer as a constructor parameter, and writes to this writer as the document is constructed.

      Unfortunatly, I think this would either require a rewrite of JsonBuilder, or a new class to handle this situation (StreamingJsonBuilder?)

        Activity

        Hide
        Tim Yates added a comment -

        Added a new class groovy.json.StreamingJsonBuilder which I believe covers this issue...

        I have also copied the tests from JsonBuilderTests to StreamingJsonBuilderTests, removed the tests for writable, and ensured they all pass (I added an extra test for passing an empty Map and a Closure to the invokeMethod call)

        Hopefully it's ok, can someone have a look and make sure I haven't missed anything? I always seem to miss something glaringly obvious

        Show
        Tim Yates added a comment - Added a new class groovy.json.StreamingJsonBuilder which I believe covers this issue... I have also copied the tests from JsonBuilderTests to StreamingJsonBuilderTests , removed the tests for writable, and ensured they all pass (I added an extra test for passing an empty Map and a Closure to the invokeMethod call) Hopefully it's ok, can someone have a look and make sure I haven't missed anything? I always seem to miss something glaringly obvious
        Hide
        Tim Yates added a comment -

        It could probably do with a better description in the javadoc description, as I just copied this verbatim from the JsonBuilder class and fixed the examples

        And wrapped the examples in <pre class="groovyTestCase"> so that they get executed by ant test

        I also guessed at 1.8.2 for the @since tag, as I realise 1.8.1 is imminent

        Show
        Tim Yates added a comment - It could probably do with a better description in the javadoc description, as I just copied this verbatim from the JsonBuilder class and fixed the examples And wrapped the examples in <pre class="groovyTestCase"> so that they get executed by ant test I also guessed at 1.8.2 for the @since tag, as I realise 1.8.1 is imminent
        Hide
        blackdrag blackdrag added a comment -

        this one is for Guillaume

        Show
        blackdrag blackdrag added a comment - this one is for Guillaume
        Hide
        Guillaume Laforge added a comment -

        Thanks a lot Tim!

        Show
        Guillaume Laforge added a comment - Thanks a lot Tim!

          People

          • Assignee:
            Guillaume Laforge
            Reporter:
            Tim Yates
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: