# JSONObject cannot be cast to class java.io.Serializable

**URL:** <https://forum.inductiveautomation.com/t/jsonobject-cannot-be-cast-to-class-java-io-serializable/41248>\
**Category:** Module Development\
**Created:** [December 6, 2020, 9:11pm UTC](https://forum.inductiveautomation.com/t/jsonobject-cannot-be-cast-to-class-java-io-serializable/41248 "2020-12-06T21:11:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bebel](https://avatars.discourse-cdn.com/v4/letter/b/43a26b/32.png) [@bebel](https://forum.inductiveautomation.com/u/bebel)\
**Post date:** [December 6, 2020, 9:11pm UTC](https://forum.inductiveautomation.com/t/jsonobject-cannot-be-cast-to-class-java-io-serializable/41248/1 "2020-12-06T21:11:43Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [December 6, 2020, 9:22pm UTC](https://forum.inductiveautomation.com/t/jsonobject-cannot-be-cast-to-class-java-io-serializable/41248/2 "2020-12-06T21:22:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bebel](https://avatars.discourse-cdn.com/v4/letter/b/43a26b/32.png) [@bebel](https://forum.inductiveautomation.com/u/bebel)\
**Post date:** [December 6, 2020, 9:23pm UTC](https://forum.inductiveautomation.com/t/jsonobject-cannot-be-cast-to-class-java-io-serializable/41248/3 "2020-12-06T21:23:55Z")

</div>

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