I have a string which looks like:
text = " "12.10 On-Going Submission of ""Made Up"" Samples." "
I am trying to escape the double quotes. I have tried the following thing:
import groovy.json.StringEscapeUtils;
textFinal: escapeJava(text)
BTW this text is going to be a JSON response. I am getting the following error as JSON response
groovy.lang.MissingMethodException: No signature of method: com.thomsonreuters.ald.aeandsdx.ArtifactController.escapeJava() is applicable for argument types: (java.lang.String) values: ["12.10 On-Going Submission of ""Made Up"" Samples."]{"status":"Bad request","msg":{"arguments":["\"12.10 On-Going Submission of\"\"
on the console I am getting this error :
2014-09-25 14:55:07,555 [http-bio-8080-exec-1] ERROR errors.GrailsExceptionResolver - StringIndexOutOfBoundsException occurred when processing request: [GET] /artifact - parameters:
documentName: ICENSE AGREEMENT6
String index out of range: -25. Stacktrace follows:
Message: String index out of range: -25
Line | Method
->> 1911 | substring in java.lang.String
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1946 | subSequence in ''
| 1042 | append . . . . in java.io.PrintWriter
| 56 | append in ''
| 180 | value . . . . in grails.converters.JSON
| 162 | convertAnother in ''
| 202 | value . . . . in ''
| 162 | convertAnother in ''
| 202 | value . . . . in ''
| 162 | convertAnother in ''
| 202 | value . . . . in ''
| 134 | render in ''
| 150 | render . . . . in ''
| 328 | $tt__index in com.thomsonreuters.ald.aeandsdx.ArtifactController
| 198 | doFilter . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 1145 | runWorker . . in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run . . . . . in java.lang.Thread
Don't know why this wont work. This should. To get more clear picture what exactly I am trying to do refer Question 1 Question 2 and Question 3
Currently you're just importing StringEscapeUtils
in a regular way, but then you're not explicitly calling the method from the right class.
I suspect you either want:
import static groovy.json.StringEscapeUtils.escapeJava;
textFinal: escapeJava(text)
or:
import groovy.json.StringEscapeUtils;
textFinal: StringEscapeUtils.escapeJava(text)
See more on this question at Stackoverflow