Skip to Content
0
Jul 11, 2019 at 04:57 PM

unable to resolve class JsonGenerator

1202 Views

Hi,

I have this very simple groovy script:

----------------------------------------------------------

import groovy.json.JsonBuilder;
import groovy.json.JsonGenerator;

def id = " ";

def generator = new JsonGenerator.Options()
.excludeNulls()
.build()

JsonBuilder builder = new JsonBuilder(generator)
builder {

name id?.trim() ? id : null
make 'Holden'
year 2006
country 'Australia'
}

println builder.toString();

----------------------------------------------------------

There is nothing wrong in the code but I get this error when I ran it in CPI:

javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: buildJsonForUpdatedFields__Script.gsh: 4: unable to resolve class groovy.json.JsonGenerator

Is there a way to upgrade the groovy version? Or is there a way to explicitly use the latest groovy version, if yes how??