Code example for NotSerializableException

0
        key = new OpenSSLKey(NativeCrypto.EVP_PKEY_new_mac_key(type, encoded));
    } 
 
    private void writeObject(ObjectOutputStream stream) throws IOException {
        if (getOpenSSLKey().isEngineBased()) { 
            throw new NotSerializableException("engine-based keys can not be serialized");
        } 
 
        stream.defaultWriteObject();
    } 
}