SerializableUtils { public static Object deserializeFromByteArray(byte[] encodedValue, String description) { try { try (ObjectInputStream ois = new ContextualObjectInputStream( new SnappyInputStream(new ByteArrayInputStream(encodedValue)))) { return ois.readObject(); } } catch (IOException | ClassNotFoundException exn) { throw new IllegalArgumentException("unable to deserialize " + description, 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 testDeserializationError() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("unable to deserialize a bogus string"); SerializableUtils.deserializeFromByteArray( "this isn't legal".getBytes(Charsets.UTF_8), "a bogus string"); }