@Test void shouldFailIfNotSerializable() { InvalidArgumentException ex = assertThrows( InvalidArgumentException.class, () -> SerializableTranscoder.INSTANCE.encode(new Group()) ); assertTrue(ex.getCause() instanceof NotSerializableException); }
@Override public EncodedValue encode(Object input) { try { final ByteArrayOutputStream bos = new ByteArrayOutputStream();; final ObjectOutputStream os = new ObjectOutputStream(bos); os.writeObject(input); final byte[] serialized = bos.toByteArray(); os.close(); bos.close(); return new EncodedValue(serialized, CodecFlags.SERIALIZED_COMPAT_FLAGS); } catch (Exception ex) { throw InvalidArgumentException.fromMessage("Could not encode (serialize) the given object!", ex); } }
SerializableTranscoder implements Transcoder { @Override public EncodedValue encode(Object input) { try { final ByteArrayOutputStream bos = new ByteArrayOutputStream();; final ObjectOutputStream os = new ObjectOutputStream(bos); os.writeObject(input); final byte[] serialized = bos.toByteArray(); os.close(); bos.close(); return new EncodedValue(serialized, CodecFlags.SERIALIZED_COMPAT_FLAGS); } catch (Exception ex) { throw InvalidArgumentException.fromMessage("Could not encode (serialize) the given object!", ex); } } }
SerializableTranscoder implements Transcoder { @Override public EncodedValue encode(Object input) { try { final ByteArrayOutputStream bos = new ByteArrayOutputStream();; final ObjectOutputStream os = new ObjectOutputStream(bos); os.writeObject(input); final byte[] serialized = bos.toByteArray(); os.close(); bos.close(); return new EncodedValue(serialized, CodecFlags.SERIALIZED_COMPAT_FLAGS); } catch (Exception ex) { throw InvalidArgumentException.fromMessage("Could not encode (serialize) the given object!", ex); } } private  SerializableTranscoder(); }
SerializableTranscoder implements Transcoder { @Override public EncodedValue encode(Object input) { try { final ByteArrayOutputStream bos = new ByteArrayOutputStream();; final ObjectOutputStream os = new ObjectOutputStream(bos); os.writeObject(input); final byte[] serialized = bos.toByteArray(); os.close(); bos.close(); return new EncodedValue(serialized, CodecFlags.SERIALIZED_COMPAT_FLAGS); } catch (Exception ex) { throw InvalidArgumentException.fromMessage("Could not encode (serialize) the given object!", ex); } } private  SerializableTranscoder(); @Override EncodedValue encode(Object input); @Override @SuppressWarnings("unchecked") T decode(Class<T> target, byte[] input, int flags); }
SerializableTranscoder implements Transcoder { @Override public EncodedValue encode(Object input) { try { final ByteArrayOutputStream bos = new ByteArrayOutputStream();; final ObjectOutputStream os = new ObjectOutputStream(bos); os.writeObject(input); final byte[] serialized = bos.toByteArray(); os.close(); bos.close(); return new EncodedValue(serialized, CodecFlags.SERIALIZED_COMPAT_FLAGS); } catch (Exception ex) { throw InvalidArgumentException.fromMessage("Could not encode (serialize) the given object!", ex); } } private  SerializableTranscoder(); @Override EncodedValue encode(Object input); @Override @SuppressWarnings("unchecked") T decode(Class<T> target, byte[] input, int flags); static SerializableTranscoder INSTANCE; }