Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-5323

JsonOutput.prettyPrint breaks escaped special characters

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.8.6
    • 2.0-beta-3, 1.8.7
    • JSON
    • None

    Description

      I suppose that json text filtered with groovy.json.JsonOutput.prettyPrint should produce again valid JSON string. Try this example/testcase and see how prettyPrint breaks escaped characters:

      String json = new groovy.json.JsonBuilder('a': 'x"y').toString()
      String pretty = groovy.json.JsonOutput.prettyPrint(json)
      
      // comment this println in final test case
      println json
      println pretty
      
      def slurper = new groovy.json.JsonSlurper()
      // this is OK in 1.8.6
      try {
        def test1 = slurper.parseText(json)
        assert 'x"y' == test1.a
      } catch(Exception e) {
        assert false, "parsing generated JSON failed"
      }
      // this fails in 1.8.6
      try {
        def test = slurper.parseText(pretty)
        println test.a
      } catch(Exception e) {
        assert false, "parsing pretty printed JSON failed"
      }
      

      Attachments

        Activity

          People

            guillaume Guillaume Sauthier
            jakub.neubauer Jakub Neubauer
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: