public void write(Packer packer, Object v, boolean required)
            throws IOException {
        if (v == null) {
            if (required) {
                throw new MessageTypeException("Attempted to write null");
            }
            packer.writeNil();
            return;
        }
        if (!(v instanceof Object[]) ||
                !componentClass.isAssignableFrom(v.getClass().getComponentType())) {
            throw new MessageTypeException();
        }

        Object[] array = (Object[]) v;
        int length = array.length;
        packer.writeArrayBegin(length);
        for (int i = 0; i < length; i++) {
            componentTemplate.write(packer, array[i], required);
        }
        packer.writeArrayEnd();
    }