I’m creating a service class in grails that generates a JSON structure and uses it to do a REST call to another service. I’m trying to import some groovy.json classes as follows:
import groovy.json.JsonBuilder
import groovy.json.JsonOutput
class SomeService {
...
}
But, I’m get the following error:
1: unable to resolve class groovy.json.JsonBuilder
[groovyc] @ line 1, column 1.
[groovyc] import groovy.json.JsonBuilder
[groovyc] ^
When I try in groovysh, it seems to import these classes just fine. What do I need to do to pull in the standard Groovy JSON library in Grails?
That class was introduced in Groovy 1.8 which isn’t used in Grails until 2.0.0+. You’ll need to either upgrade to 2.0.x+ or use a different JSON library.