@SuppressWarnings({"unchecked", "rawtypes"})
    @Override
    public void encode(Object bean, CodedOutputStream output) throws ConverterException {
        try {
            Object obj = field.get(bean);
            if (obj != null) {
                ByteArrayOutputStream bout = new ByteArrayOutputStream();
                CodedOutputStream innerOutput = CodedOutputStream
                        .newInstance(bout);
                try {
                    Converter itemConverter = converters.get(obj.getClass());
                    if (itemConverter == null) {
                        throw new RuntimeException("No converter provided for "
                                + bean.getClass().getName());
                    }
                    byte[] bytes = (byte[]) itemConverter.encode(obj);
                    innerOutput.writeString(CLASS_NAME, obj.getClass()
                            .getName());
                    innerOutput.writeBytes(OBJECT, ByteString.copyFrom(bytes));
                    innerOutput.flush();
                    output.writeBytes(id,
                            ByteString.copyFrom(bout.toByteArray()));
                } catch (IOException | RuntimeException e) {
                    throw new ConverterException("Could not write '"
                            + field.getName() + "' to byte array!", e);
                } finally {
                    try {
                        bout.close();
                    } catch (IOException e) {
                        throw new RuntimeException(
                                "Could not close output stream!", e);
                    }
                }
            }
        } catch (IllegalAccessException | RuntimeException e) {
            throw new ConverterException("Exception during serialization", e);
        }
    }