0

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

Community
  • 1
  • 1
krs8785
  • 1,017
  • 2
  • 13
  • 24

1 Answers1

0

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)
Jon Skeet
  • 1,335,956
  • 823
  • 8,931
  • 9,049
  • I did the latter one but my JSON go truncated { "documentName":"ICENSE AGREEMENT6", "listOfArtifacts":[ { "type":"Clause", "artifacts":[ { "documentId":6951, "documentName":"ICENSE AGREEMENT6", "artifactId":7029, "text":"\\\"12.10 On-Going Submission o\\\"\\\"" – krs8785 Sep 25 '14 at 19:09
  • @krs: That sounds like it's probably either just your logging, or your input being truncated. I very much doubt that it's got anything to do with the escaping part. – Jon Skeet Sep 25 '14 at 19:18
  • When you say input being truncated, i do get an string index out of bound error on the console too. – krs8785 Sep 25 '14 at 19:22
  • ok i got you.. what you say is correct. i did get the esacping right. I jsut printed the text and its perfect. \"12.10 On-Going Submission of \"\"Made Up\"\" Samples.\". But why is the JSON getting truncated – krs8785 Sep 25 '14 at 19:34
  • @krs: I have no way of knowing that, but it sounds like a different question, and one that you should ask in a different post. – Jon Skeet Sep 25 '14 at 19:36
  • is it because i render it again as JSON at the end ? – krs8785 Sep 25 '14 at 19:36
  • @krs: I can't possibly tell, because all I've got is those two lines of code. But again, that's off the topic of this question. *Please* take the hint and start a new question with all the relevant details. – Jon Skeet Sep 25 '14 at 19:38
  • http://stackoverflow.com/questions/26047623/json-get-truncated-in-rest-service-possible-because-of-double-quotes – krs8785 Sep 25 '14 at 20:34