public static void serialize(final Serializable obj, final OutputStream outputStream) {
        Validate.isTrue(outputStream != null, "The OutputStream must not be null");
        try (ObjectOutputStream out = new ObjectOutputStream(outputStream)){
            out.writeObject(obj);
        } catch (final IOException ex) {
            throw new SerializationException(ex);
        }
    }
public static void serialize ( final Serializable obj , final OutputStream outputStream ) { Validate . isTrue ( outputStream != null , "The OutputStream must not be null" ) ; try ( ObjectOutputStream out = new ObjectOutputStream ( outputStream ) ) { out . writeObject ( obj ) ; } catch ( final IOException ex ) { throw new SerializationException ( ex ) ; } }
<p>Serializes an {@code Object} to the specified stream.</p>

<p>The stream will be closed once the object is written.
This avoids the need for a finally clause, and maybe also exception
handling, in the application code.</p>

<p>The stream passed in is not buffered internally within this method.
This is the responsibility of your application if desired.</p>

@param obj  the object to serialize to bytes, may be null
@param outputStream  the stream to write to, must not be null
@throws IllegalArgumentException if {@code outputStream} is {@code null}
@throws SerializationException (runtime) if the serialization fails