You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by Guy Matz <gu...@gmail.com> on 2016/04/27 18:36:30 UTC

RESTClient error when POSTing JSON with embedded GString

Hi!  The code below chokes when I try to use the GString "${build.number}"
within the fields var.  The error I get is:
Apr 27, 2016 12:32:25 PM net.sf.json.JSONObject _fromBean
INFO: Property 'value' of class org.codehaus.groovy.runtime.GStringImpl has
no read method. SKIPPED

Anyone know what I'm doing wrong there?  Works fine when i use a regular
string

import groovyx.net.http.RESTClient
import static groovyx.net.http.ContentType.JSON

def build=['number':456]
def changes=['data':'123 -> 124', 'render':'234 -> 235','web':'678 -> 679']
def jiraUser='jira'
def jiraPassword='password'
def changelog='ch-ch-ch-ch-changes'

def jiraProject = 'Change Management System'
def jiraProjectCode = 'CMS'
def *fields* = ['project': [key:'CMS'],
   'issuetype': [name:'Continuous Delivery'],
   // 'summary': "Changes in QA Deploy ",
   'summary': "Changes in QA Deploy #*${build.number}*",
   'description': changelog,
   'customfield_20904': build.number.toString(),
   'customfield_20905': changes['data'],
   'customfield_20906': changes['render'],
   'customfield_20907': changes['web']
]
def reqParams = [
  fields : fields
]

def jiraServer = 'https://stage.atlassian.net'
def createTicketPath = '/rest/api/latest/issue'

def rest = new RESTClient(jiraServer)
rest.headers['Authorization'] = 'Basic
'+"${jiraUser}:${jiraPassword}".bytes.encodeBase64()

try {
  println "Attempting REST call with . . ." + reqParams
  def resp = rest.post( path : createTicketPath, body: reqParams,
contentType: JSON)
  println resp.status
  println resp.data
}
catch(Exception e) {
  println "ERROR!!! " + e
}

Re: RESTClient error when POSTing JSON with embedded GString

Posted by Emmanuel Rosa <go...@gmail.com>.
That’s coming from the defaultBeanProcessing() method in JSONObject: https://github.com/aalmiray/Json-lib/blob/9e2b3376ee8f511a48aa7ac05f75a7414e02280f/src/main/jdk15/net/sf/json/JSONObject.java#L729 <https://github.com/aalmiray/Json-lib/blob/9e2b3376ee8f511a48aa7ac05f75a7414e02280f/src/main/jdk15/net/sf/json/JSONObject.java#L729>

It seems like JSONObject is tripping up on the GString. My guess is that it doesn’t see it as a String, and therefore attempts to treat it like a bean. I couldn’t verify this theory because for some reason json-lib is not resolving for me via @Grab. But, try doing a toString() on that GString.

> On Apr 27, 2016, at 12:36 PM, Guy Matz <gu...@gmail.com> wrote:
> 
> net.sf.json.JSONObject _fromBean