public static byte[] serialize(Serializable obj) {
ObjectOutputStream oos = null;
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
oos.writeObject(obj);
return baos.toByteArray();
} catch (NotSerializableException e) {
throw new IllegalStateException(e.getMessage());
} catch (IOException e) {
throw new IllegalStateException(e.getMessage());