title: Needing to mock a closed source web application (sailpoint) best way to dump objects not marked as serializable in this case?
body: <p>I've been developing beanshell code in a local environment with VSCode using plain java, but in order to do so I've needed to dump the objects sailpoint passes to the beanshell environment (such as SailpointContext, SailpointObject, WorkflowContext, etc.)</p>
  <p>They were dumped with code like this:</p>
  <pre class="lang-java prettyprint-override"><code>FileOutputStream f = new FileOutputStream(new File(&quot;.\\test\\objects\\test.&quot; + obj.getName() + &quot;--&quot; + obj.getClass().getCanonicalName() + &quot;.javaObject&quot;));
  ObjectOutputStream o = new ObjectOutputStream(f);
  o.writeObject(obj);
  </code></pre>
  <p>I created an extension class for SailpointContext, which loads up those objects using code like:</p>
  <pre class="lang-java prettyprint-override"><code>@Override
  public &lt;T extends SailPointObject&gt; T getObjectByName(Class&lt;T&gt; c, String name) throws GeneralException {
    return getObjectFromFile(c, name);
  }
  </code></pre>
  <p>I then load these up using mockito, which then runs the java code in unit tests. For example:</p>
  <pre class="lang-java prettyprint-override"><code>Identity manager = Mockito.spy(context.getObjectByName(Identity.class, &quot;janedoe&quot;));
  Identity identity = Mockito.spy(context.getObjectByName(Identity.class, &quot;johnsmith&quot;));
  Mockito.doReturn(manager).when(identity).getManager();
  </code></pre>
  <p>In a recent version of Sailpoint however, they stopped implementing the java.io.Serializable marker class for many of the classes they use, so this method of dumping them no longer works in many cases. Are there any decent ways of dumping these objects when they're not not marked that way? I looked at Kryo, but it fails on org.hibernate.LazyInitializationException as many of the method calls make internal database references. The built-in java way would still dump them anyways, but if I tried to call those methods in my test environment then that is where they would throw the org.hibernate.LazyInitializationException rather than on the server where I was dumping them from, and Mockito.doReturn was my way around that in the test setting (i.e. just pre-dump the objects that my script is going to reference, and then insert them prior to the test running.)</p>