Skip to Content

unable to resolve class JsonGenerator


I have this very simple groovy script:


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

def id = " ";

def generator = new JsonGenerator.Options()

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??

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Posted on Jul 11, 2019 at 05:32 PM

    This is resolved.

    The only thing I need to do is to upload the "groovy-json-2.5.7.jar" file on the resource tab as archive and that's it. No need to change any code for import.

    You can download the file here:

    Add a comment
    10|10000 characters needed characters exceeded

    • Hello Jeremy

      I just imported the ".jar" mentioned, and I get the following error.

      An internal server error occured: tried to access field groovy.json.JsonOutput.EMPTY_STRING_CHARS (class loader org.apache.felix.framework.BundleWiringImpl$BundleClassLoader@135556, resolved org.apache.felix.framework.BundleWiringImpl$BundleClassLoader@135556) from class groovy.json.DefaultJsonGenerator (class loader
      The MPL ID for the failed message is : AF2pCriOQztyhB_Lp9fp8Vsq68rj
      For more details please check tail log.

      Any ideas to solve this error.

      Thank you,


      screenshot-1.png (4.8 kB)

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.