JsonNull value cannot be cast to JsonObject
I have a custom connector where I execute queries and retrieve information from a database
When i execute a query say like select name where name like 'bonita', if there is any result, then i get a response and store it in a variable without any problem
If the response is null, i use an if else condition to return something. But i get the following error if the response is null.
if else condition is as follows:
try{
if(response.get(0).get(0)==null)){
return "No result";
}
else return response.get(0).get(0) ;
}
catch(Exception e){
return false;
}
Error:
Caused by: java.util.concurrent.ExecutionException: java.lang.ClassCastException: com.google.gson.JsonNull cannot be cast to com.google.gson.JsonObject
at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:262)
at java.util.concurrent.FutureTask.get(FutureTask.java:119)
at com.bonitasoft.engine.connector.impl.ConnectorExecutorTimedOut.getValue(ConnectorExecutorTimedOut.java:54)
at org.bonitasoft.engine.connector.impl.ConnectorExecutorImpl.execute(ConnectorExecutorImpl.java:122)
... 13 more
Caused by: java.lang.ClassCastException: com.google.gson.JsonNull cannot be cast to com.google.gson.JsonObject
at com.google.gson.JsonObject.getAsJsonObject(JsonObject.java:186)
at be.bonita7.connector.TestImpl.executeBusinessLogic(TestImpl.java:119)
at org.bonitasoft.engine.connector.AbstractConnector.execute(AbstractConnector.java:77)
at org.bonitasoft.engine.core.connector.impl.SConnectorAdapter.execute(SConnectorAdapter.java:69)
at org.bonitasoft.engine.connector.impl.ConnectorExecutorImpl$ExecuteConnectorCallable.call(ConnectorExecutorImpl.java:208)
at org.bonitasoft.engine.connector.impl.ConnectorExecutorImpl$ExecuteConnectorCallable.call(ConnectorExecutorImpl.java:179)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
... 3 more
Any help would be really appreciated.
Regards,
A.
You can't test for nothing when nothing exists...
You need to change your code to something like this.
While(recordset.next()){
//Do record processing
Set returnstatus = get(0);
}
Return returnstatus;
This will work because while recordset.next() works for a null recordset,
Regards
Seán
PS: as this answers your question, please mark as resolved.
Comments
Hi,
Recordset doesnt seem to work in groovvy script.
Unable to resolve class is the error i get when i use the following code.
Any idea how i can overcome this error?
Thanks.
yep it works for me...the code I gave was only a sample, you'll need to provide the correct code...
Don't forget to import things like
java.sql.ResultSet etc...
into you groovy script.
regards
PS: