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

JsonBuilder toPrettyString gen "\"\"" for emtyString it should be ""

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.0
    • Fix Version/s: 2.1.0-rc-2, 2.1.0, 2.0.7
    • Component/s: JSON
    • Labels:
      None
    • Environment:
      window 7

      Description

            def builder = new groovy.json.JsonBuilder()
              def root = builder.people {
                  firstName 'Guillame'
                  lastName 'Laforge'
                  married true
                  conferences 'JavaOne', 'Gr8conf'
                  blank ''
              }
              println builder.toString()
              println builder.toPrettyString()
      
              String s = '""'
              println "$s"
              println "${s[1..-2]}"
              println "${StringEscapeUtils.escapeJava(s[1..-2])}"
      

      output

      {"people":{"firstName":"Guillame","lastName":"Laforge","married":true,"conferences":["JavaOne","Gr8conf"],"blank":""}}
      {
          "people": {
              "firstName": "Guillame",
              "lastName": "Laforge",
              "married": true,
              "conferences": [
                  "JavaOne",
                  "Gr8conf"
              ],
              "blank": "\"\""
          }
      }
      ""
      ""
      \"\"
      

      I think there is a bug on file "D:\groovy-src-2.0.4\groovy-2.0.4\subprojects\groovy-json\src\main\groovy\groovy\json\JsonOutput.groovy"

      line 190-192

           } else if (token.type == STRING) {
                      output.append('"' + StringEscapeUtils.escapeJava(token.text[1..-2]) + '"')
      

        Attachments

        1. testString1.groovy
          0.7 kB
          chokchai chalermwattanatrai

          Activity

            People

            • Assignee:
              paulk Paul King
              Reporter:
              chokchai chokchai chalermwattanatrai
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: