public byte[] serialize(Object source) {
        if (source == null) {
            String msg = "argument cannot be null.";
            throw new IllegalArgumentException(msg);
        }

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(bos));
        encoder.writeObject(source);
        encoder.close();

        return bos.toByteArray();
    }
Serializes the specified <code>source</code> into a byte[] array by using the
{@link java.beans.XMLEncoder XMLEncoder} to encode the object out to a
{@link java.io.ByteArrayOutputStream ByteArrayOutputStream}, where the resulting byte[] array is returned.

@param source the Object to convert into a byte[] array.
@return the byte[] array representation of the XML encoded output.
lang/src/main/java/org/apache/shiro/lang/io/XmlSerializer.java