Support Article
Unable to compile org.json.JSONObject library
SA-54376
Summary
User is trying to convert Pega Clipboard page to JSON object to use in Connect-REST rule.
After converting Clipboard page in JSON Object, user is also removing pxObjClass using new function rule created using org.json.JSONObject.
They are able to generate the library and function in Developer environment, but the same is throwing an error in System integration testing (SIT) environment.
Error Messages
Error(s) detected while generating java. Compiler reported: ----------
ERROR in com/pegarules/generated/test_RemoveElementFromJSON_010605_KpaCW2YJfeHfYTAhoa5FxQ.java (at line 103, line 109, line 110) , (at line 111), (at line 112), (at line 114), (at line 115),(at line 124)
org.json.JSONObject jo=new org.json.JSONObject(jsonSource);
^^^^^^^^^^^^^^^^^^^
org.json.JSONObject cannot be resolved to a type
----------
Steps to Reproduce
Generate the library having new function.
Root Cause
The jar related to org.json.JSONObject is missing in the environment.
Resolution
Make the following change to the operating environment:
Import the proper jar.
After importing the custom function is not working properly, then use the below function to remove pxobjclass:
json = json.replaceAll("\"" + prop + "\"[ ]*:[^,}\\]]*[,]?", "")
json is the string containing the json data and prop is the key that you want to remove. This works perfectly for a single valued key like pxobjclass.
Published July 23, 2018 - Updated October 8, 2020
Have a question? Get answers now.
Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.