BlobValueCodec implements ValueCodec<Object, Object> { @Override @SneakyThrows public Object encode(Object value) { if (value == null) { return null; } if (value instanceof Blob) { return (value); } if (!(value instanceof byte[])) { if (value instanceof Serializable) { try (ByteArrayOutputStream output = new ByteArrayOutputStream(); ObjectOutputStream object = new ObjectOutputStream(output)) { object.writeObject(value); object.flush(); object.close(); value = output.toByteArray(); } } else { throw new NotSerializableException("unsupported encode type " + value.getClass()); } } return ( value); }  @Override @SneakyThrows Object encode(Object value); @Override @SneakyThrows Object decode(Object data); static final BlobValueCodec INSTANCE; }
@Test public void testError() { BlobValueCodec codec = new BlobValueCodec(); try { codec.encode(new Object()); fail(); } catch (Exception e) { assertTrue(e instanceof NotSerializableException); } }