# Driver Module Scope Best Practice

**URL:** <https://forum.inductiveautomation.com/t/driver-module-scope-best-practice/44799>\
**Category:** Module Development\
**Tags:** ignition80\
**Created:** [March 23, 2021, 3:18pm UTC](https://forum.inductiveautomation.com/t/driver-module-scope-best-practice/44799 "2021-03-23T15:18:52Z")\
**Posts on this page:** 1\
**Showing post:** 16

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [April 5, 2021, 6:50pm UTC](https://forum.inductiveautomation.com/t/driver-module-scope-best-practice/44799/16 "2021-04-05T18:50:04Z")

</div>

> [@pturmel](#):
>
> Definitely use RPC, or a remote designer may not work. Nor any Vision clients.

I set all of this up to instantiate the connections in the gateway scope and store them in a hash map so that I can access them via name. However now I am having issues recalling the instantiated connectors with rpc. I am getting an error that the object is not serializable, and from some light research I found this comment that signifies I am potentially doing something wrong here.

> [@JSONObject cannot be cast to class java.io.Serializable](https://forum.inductiveautomation.com/t/jsonobject-cannot-be-cast-to-class-java-io-serializable/41248/2):
>
> 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.

Currently I am instantiating and storing the connector instance in the gateway scope, and then getting it via its name and passing it back through RPC. Is the issue here that I am trying to execute all of my functionality in the common scope, and instead I need to move my functionality to the gateway scope and just add methods to reach it in the common scope? Or Is passing it back via something like the following just not the correct implementation:

```auto
@Override
    protected DatabaseConnector getDatabaseConnectorImpl(String connectionName) {
        return rpc.getDatabaseConnector(connectionName);
    }

```

Here is the stack trace as well if it helps:

> **Stacktrace**
>
> ```auto
> Caused by: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: class com.bwdesigngroup.neo4j.driver.DatabaseConnector cannot be cast to class java.io.Serializable (com.bwdesigngroup.neo4j.driver.DatabaseConnector is in unnamed module of loader com.inductiveautomation.ignition.gateway.modules.ModuleClassLoader @451c1f9f; java.io.Serializable is in module java.base of loader 'bootstrap')
> at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.newGatewayException(GatewayInterface.java:359)
> at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:333)
> at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:286)
> at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.moduleInvokeSafe(GatewayInterface.java:905)
> at com.inductiveautomation.ignition.client.gateway_interface.ModuleRPCFactory$DynamicRPCHandler.invoke(ModuleRPCFactory.java:53)
> ... 27 more
> Caused by: java.lang.ClassCastException: class com.bwdesigngroup.neo4j.driver.DatabaseConnector cannot be cast to class java.io.Serializable (com.bwdesigngroup.neo4j.driver.DatabaseConnector is in unnamed module of loader com.inductiveautomation.ignition.gateway.modules.ModuleClassLoader @451c1f9f; java.io.Serializable is in module java.base of loader 'bootstrap')
> at com.inductiveautomation.ignition.gateway.servlets.gateway.functions.ModuleInvoke.invoke(ModuleInvoke.java:172)
> at com.inductiveautomation.ignition.gateway.servlets.Gateway.doPost(Gateway.java:405)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
> at com.inductiveautomation.ignition.gateway.bootstrap.MapServlet.service(MapServlet.java:86)
> at org.eclipse.jetty.servlet.ServletHolder$NotAsyncServlet.service(ServletHolder.java:1391)
> at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:760)
> at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:547)
> at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
> at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:590)
> at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
> at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235)
> at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1607)
> at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
> at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1297)
> at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
> at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:485)
> at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1577)
> at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
> at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1212)
> at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
> at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
> at org.eclipse.jetty.rewrite.handler.RewriteHandler.handle(RewriteHandler.java:322)
> at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:59)
> at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:146)
> at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
> at org.eclipse.jetty.server.Server.handle(Server.java:500)
> at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383)
> at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:547)
> at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375)
> at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:270)
> at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
> at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
> at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
> at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336)
> at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313)
> at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171)
> at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129)
> at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:388)
> at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806)
> at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938)
> at java.lang.Thread.run(null)
> 
> ```

Thanks for any help,  
Keith

---

_[View the full topic](https://forum.inductiveautomation.com/t/driver-module-scope-best-practice/44799)._
