JSONObject cannot be cast to class java.io.Serializable

I have developed a module to use a REST API. One function returns a JSONObject. I started by debugging the functions in the Abstract Script Module and everything was working fine. Then I moved the script into a Impl function in the Gateway Script Module and I started getting and error.
Traceback (most recent call last):
File “event:actionPerformed”, line 45, in
java.lang.reflect.UndeclaredThrowableException: java.lang.reflect.UndeclaredThrowableException

caused by UndeclaredThrowableException
caused by GatewayException: class org.json.JSONObject cannot be cast to class java.io.Serializable (org.json.JSONObject is in unnamed module of loader 'app'; java.io.Serializable is in module java.base of loader 'bootstrap')
caused by ClassCastException: class org.json.JSONObject cannot be cast to class java.io.Serializable (org.json.JSONObject is in unnamed module of loader 'app'; java.io.Serializable is in module java.base of loader 'bootstrap')

Ignition v8.0.14 (b2020062220)
I’m not doing any casting to Serialized in my scripting.
It seems as though the rpc is trying to convert the JSONObject?

The RPC system requires anything being sent between client/gateway to implement java.io.Serializable. JSONObject doesn’t, so it’s not something your’ll be able to return from your function if the result will be RPC’d to the client.

Thanks for the quick reply. At least that save me from wasting any more time trying to figure this out.