@SuppressWarnings("unchecked")
    @Override
    protected String expand(Object variable, boolean encode) {
      StringBuilder expanded = new StringBuilder();
      if (Iterable.class.isAssignableFrom(variable.getClass())) {
        expanded.append(this.expandIterable((Iterable<?>) variable));
      } else if (Map.class.isAssignableFrom(variable.getClass())) {
        expanded.append(this.expandMap((Map<String, ?>) variable));
      } else if (Optional.class.isAssignableFrom(variable.getClass())) {
        Optional<?> optional = (Optional) variable;
        if (optional.isPresent()) {
          expanded.append(this.expand(optional.get(), encode));
        } else {
          if (!this.nameRequired) {
            return null;
          }
          expanded.append(this.encode(this.getName())).append("=");
        }
      } else {
        if (this.nameRequired) {
          expanded.append(this.encode(this.getName())).append("=");
        }
        expanded.append((encode) ? encode(variable) : variable);
      }

      /* return the string value of the variable */
      String result = expanded.toString();
      if (!this.matches(result)) {
        throw new IllegalArgumentException(
            "Value " + expanded + " does not match the expression pattern: " + this.getPattern());
      }
      return result;
    }
Expression that adheres to Simple String Expansion as outlined in <a
href="https://tools.ietf.org/html/rfc6570#section-3.2.2>Simple String Expansion (Level 1)</a>
core/src/main/java/feign/template/Expressions.java