Thingworx Template Custom Extension, Issue with JSON String input in custom service
I have created a custom thing template which contains a service which takes data in json string, then generates a PDF report ans save it in file repository.
The issue is, when I hard code the json string inside the service, the custom extension works great. It creates report and save it to repository, But if the same json string input is passed dynamically from imported extension, it gives me the below error:
Unable to Invoke Service CreatePDFReport on PDFThing : java.lang.String cannot be cast to org.json.simple.JSONObject .
JSON String :: "{ \"Date\":\"121212\", \"Shift\":\"One\", \"TeamMembers\":\"Sachin\" }"
Please Help.
----------------------------------------------------------------------------------------------------------------------------------
Below is my JAVA code:
@ThingworxServiceDefinition(name = "CreatePDFReport", description = "", category = "", isAllowOverride = false, aspects = {
"isAsync:false" })
@ThingworxServiceResult(name = "Result", description = "", baseType = "STRING", aspects = {})
public String CreatePDFReport(
@ThingworxServiceParameter(name = "jsonStringA", description = "", baseType = "STRING", aspects = {
"isRequired:true" }) String jsonStringA) throws IOException, DocumentException, JSONException, ParseException {
_logger.trace("Entering Service: CreatePDFReport");
String DEST = "C:\\ThingworxStorage\\repository\\Test_PDF\\PDFReport.pdf";
String jsonStringTest = "{ \"Date\":\"121212\", \"Shift\":\"One\", \"TeamMembers\":\"Sachin\" }";
JSONParser parser = new JSONParser();
JSONObject myData = (JSONObject) parser.parse(jsonStringA);
//JSONObject myData = (JSONObject) parser.parse(jsonStringTest);
new PDFBoxAtom().createPdfAtom(DEST, myData); // Function which creates PDF report and save it to location DEST.
_logger.trace("Exiting Service: CreatePDFReport");
return "PDF Created";
}
Note: If I use jsonStringTest to create PDF report, it works fine But when I pass the same json string dynamically(jsonStringA), it gives me the error.

