Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-68207

Appending GString to net.sf.json.JSONArray corrupts the result

XMLWordPrintable

      In the following pipeline, I would expect that appending the variable `y` to `jsonArray` would be the same regardless if it is a Java String or a GString. Right now, I'm must call `.toString()` before appending.

       
      ```
      pipeline {
        agent any

        stages {
          stage('Test') {
            steps {
              script {
                def x = "x"
                def y = "${x}"
                def jsonArray = readJSON text: '[]'
                jsonArray << x
                jsonArray << y
                println(jsonArray)
              }
            }
          }
        }
      }
      ```

      Actual output:

      ```
      ["x",

      {"valueCount":1,"strings":["",""],"bytes":[120],"values":["x"]}

      ]
      ```

      Expected output:

      ```
      ["x","x"]
      ```
       

       

       

            Unassigned Unassigned
            jdufresne Jon Dufresne
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: