SerializableUtils { public static byte[] serializeToByteArray(Serializable value) { try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); try (ObjectOutputStream oos = new ObjectOutputStream(new SnappyOutputStream(buffer))) { oos.writeObject(value); } return buffer.toByteArray(); } catch (IOException exn) { throw new IllegalArgumentException("unable to serialize " + value, exn); } }  static byte[] serializeToByteArray(Serializable value); static Object deserializeFromByteArray(byte[] encodedValue, String description); static T ensureSerializableRoundTrip(T value); static T ensureSerializable(T value); static T clone(T value); static Coder<?> ensureSerializable(Coder<?> coder); static T ensureSerializableByCoder(Coder<T> coder, T value, String errorContext);  }
@Test public void testSerializationError() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("unable to serialize"); SerializableUtils.serializeToByteArray(new UnserializableByJava()); }