public static byte[] objectToByte(Object obj, SiddhiAppContext siddhiAppContext) {
        long start = System.currentTimeMillis();
        byte[] out = null;
        if (obj != null) {
            try {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream oos = new ObjectOutputStream(baos);
                oos.writeObject(obj);
                out = baos.toByteArray();
            } catch (IOException e) {
                log.error(ExceptionUtil.getMessageWithContext(e, siddhiAppContext) +
                        " Error when writing byte array.", e);
                return null;
            }
        }
        long end = System.currentTimeMillis();
        if (log.isDebugEnabled()) {
            log.debug("For SiddhiApp '" + siddhiAppContext.getName() + "'. Encoded in :" + (end - start) + " msec");
        }
        return out;
    }
Serializer used by {@link SnapshotService} to do Object to Byte[] conversion and vise-versa
modules/siddhi-core/src/main/java/io/siddhi/core/util/snapshot/ByteSerializer.java