Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Could not initialize class net.sf.json.JsonConfig

avatar
Rising Star

My flow transforms data in JSON format to XML format using a Groovy script in ExecuteScript processor. The script imports net.sf.json.JSON, net.sf.json.JSONSerializer and net.sf.json.xml.XMLSerializer. I included all the jars below but I get an error, "Failed to process session due to java.lang.NoClassDefFoundError:Could not initialize class net.sf.json.JsonConfig". I tried with different versions of the jar but an error still persists. Please suggest what's going wrong.

12092-jsontoxml-jars.jpg

Thanks.

1 ACCEPTED SOLUTION

avatar
Master Guru

I was able to get such a script working with those json-lib classes. I had different versions of some of those libraries though, your issue might be from using commons-collections-3.2.2 instead of 3.2.1.

I started with the dependencies (and versions) listed here, and only downloaded what I needed to get things compiling:

12113-json-lib-deps.png

I set the Module Directory property to the folder containing all the JARs (versus an entry for each JAR):

/Users/mburgess/Downloads/json-lib

Here is the sample script I used (it's not pretty but compiles and runs):

import net.sf.json.*
import net.sf.json.xml.*
class POGO {
  String a
  List<String> b
  Map<String, Integer> c
}
def js = new JSONSerializer()
def xs = new XMLSerializer()
def flowFile = session.get()
if(!flowFile) return
def p = new POGO(a: "Hello", b: ["I", "am", "a", "list"], c: ['k1':1, 'k2':2])
def j = js.toJSON(p)
def x = xs.write(j)
flowFile = session.putAttribute(flowFile, 'new.value', x)
session.transfer(flowFile, REL_SUCCESS)

This ignores the incoming flow file content and creates an Object which is transformed to JSON then XML (I wanted to exercise the toJSON() and write() methods), then puts the XML in an attribute (to make the example easier) and sends the flow file on.

View solution in original post

4 REPLIES 4

avatar
Rising Star

hey @spdvnz, any chance you could attach the whole stack trace? that is probably the class you're trying to initialize but it may have other dependencies

avatar
Rising Star

Sorry, I cannot copy the log but I see the below error message. Nothing else.

"failed to process session due to java.lang.NoClassDefFoundError: org/apache/commons/collections/map/ListOrderedMap: java lang.NoClassFoundError: org/apache/commons/collections/map/ListOrderedMap" .

avatar
Master Guru

I was able to get such a script working with those json-lib classes. I had different versions of some of those libraries though, your issue might be from using commons-collections-3.2.2 instead of 3.2.1.

I started with the dependencies (and versions) listed here, and only downloaded what I needed to get things compiling:

12113-json-lib-deps.png

I set the Module Directory property to the folder containing all the JARs (versus an entry for each JAR):

/Users/mburgess/Downloads/json-lib

Here is the sample script I used (it's not pretty but compiles and runs):

import net.sf.json.*
import net.sf.json.xml.*
class POGO {
  String a
  List<String> b
  Map<String, Integer> c
}
def js = new JSONSerializer()
def xs = new XMLSerializer()
def flowFile = session.get()
if(!flowFile) return
def p = new POGO(a: "Hello", b: ["I", "am", "a", "list"], c: ['k1':1, 'k2':2])
def j = js.toJSON(p)
def x = xs.write(j)
flowFile = session.putAttribute(flowFile, 'new.value', x)
session.transfer(flowFile, REL_SUCCESS)

This ignores the incoming flow file content and creates an Object which is transformed to JSON then XML (I wanted to exercise the toJSON() and write() methods), then puts the XML in an attribute (to make the example easier) and sends the flow file on.

avatar
Rising Star

Using commons-collections-3.2.1 solved the issue.Thanks, @Matt Burgess.