SerializableUtils { public static byte[] serializeToByteArray(Object value) { try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); try (ObjectOutputStream oos = new ObjectOutputStream(buffer)) { oos.writeObject(value); } return buffer.toByteArray(); } catch (IOException exn) { throw new IllegalArgumentException("unable to serialize " + value, exn); } }  static byte[] serializeToCompressedByteArray(Object value); static byte[] serializeToByteArray(Object value); static Object deserializeFromByteArray(byte[] encodedValue,
                                                  String description); static Object deserializeFromCompressedByteArray(byte[] encodedValue,
                                                            String description); static T ensureSerializable(T value); static T clone(T value);  }
@Test(expected = IllegalArgumentException.class) public void testUnserializableObject() { SerializableUtils.serializeToByteArray(new Object()); }