JSONObject cannot be cast to class java.io.Serializable

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.