public static byte [ ] serialize ( Object obj ) throws IOException { if ( obj == null ) { return null ; } try ( ByteArrayOutputStream b = new ByteArrayOutputStream ( ) ) { try ( ObjectOutputStream o = new ObjectOutputStream ( b ) ) { o . writeObject ( obj ) ; } return b . toByteArray ( ) ; } }
Serializes an object into a byte array . When the object is null returns null .