@Override
    protected byte[] internalSerializeToBytes(final Object o) {
        byte[] bytes = null;
        try (val baos = new ByteArrayOutputStream();
             ObjectOutput oos = new ObjectOutputStream(baos)) {
            oos.writeObject(o);
            oos.flush();
            bytes = baos.toByteArray();
        } catch (final IOException e) {
            LOGGER.warn("cannot Java serialize object", e);
        }
        return bytes;
    }
{@inheritDoc}

Serialize a Java object into a bytes array.
pac4j-core/src/main/java/org/pac4j/core/util/serializer/JavaSerializer.java