docs: public void writeExternal(final ObjectOutput out) throws IOException {
          ObjectOutput droolsStream;
          boolean isDrools = out instanceof DroolsObjectOutputStream;
          ByteArrayOutputStream bytes;
  
          out.writeBoolean( isDrools );
          if (isDrools) {
              droolsStream = out;
              bytes = null;
          } else {
              bytes = new ByteArrayOutputStream();
              droolsStream = new DroolsObjectOutputStream(bytes);
          }
  
          // must write this option first in order to properly deserialize later
          droolsStream.writeBoolean(this.config.isClassLoaderCacheEnabled());
  
          droolsStream.writeObject(((ProjectClassLoader) rootClassLoader).getStore());
  
          droolsStream.writeObject(this.config);
          droolsStream.writeObject(this.pkgs);
  
          // Rules must be restored by an ObjectInputStream that can resolve using a given ClassLoader to handle seaprately by storing as
          // a byte[]
          droolsStream.writeObject(this.id);
          droolsStream.writeInt(this.workingMemoryCounter.get());
          droolsStream.writeObject(this.processes);
          droolsStream.writeUTF(this.factHandleFactory.getClass().getName());
          droolsStream.writeObject(buildGlobalMapForSerialization());
  
          this.eventSupport.removeEventListener(KieBaseEventListener.class);
          droolsStream.writeObject(this.eventSupport);
  
          droolsStream.writeObject(this.reteooBuilder);
          droolsStream.writeObject(this.rete);
  
          droolsStream.writeObject(this.resolvedReleaseId);
  
          if (!isDrools) {
              droolsStream.flush();
              droolsStream.close();
              bytes.close();
              out.writeObject(bytes.toByteArray());
          }
      }