I found, that sending JSON, which has entry which starts with "function" produces invalid JSON.
Example:
@Grab('org.codehaus.groovy.modules.http-builder:http-builder:0.7.1')
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
import groovyx.net.http.RESTClient
import static groovyx.net.http.ContentType.JSON
def jsonSlurper = new JsonSlurper()
// if you replace `function` on next line to any other word - it will work correctly
String baseContextJSON = '{ "afterResponse": "function (getParam, setParam, genInfo) { }" }'
def baseContext = jsonSlurper.parseText(baseContextJSON)
println JsonOutput.prettyPrint(JsonOutput.toJson(baseContext))
RESTClient http = new RESTClient('https://requestinspector.com')
http.post(
path: "/inspect/01dh7rs82be884ke89jcny061e",
body: baseContext, // if I use baseContextJSON here - correct JSON would be sent
query: null,
requestContentType: JSON
)
This code sends this payload:
{"afterResponse":function(getParam,setParam,genInfo){}}
That's invalid JSON - note missing quote around function.
You can see actual received payloads at https://requestinspector.com/p/01dh7rs82be884ke89jcny061e (until it expires, or you can generate you own)
I can't even figure out:
- is it bug in HTTPBuilder?
- is it bug in how Groovy handles and convert Map to JSON?
Any idea what can I do to pin root cause?