code: public static <T> String requiredStringOfType(Map<String, T> map, String key, String type) {
          if (!map.containsKey(key)) {
              String message = String.format("Missing required %s value for key \"%s\".",
                                             type,
                                             key);
              throw new NoSuchElementException(message);
          }
  
          Object value = map.get(key);
  
          if (value == null) {
              return null;
          }
  
          if (value instanceof String) {
              return (String) value;
          }
  
          String message = String.format("Value \"%s\" of class \"%s\" for key \"%s\" must be a string.",
                                         value,
                                         value.getClass().getName(),
                                         key);
          throw new IllegalArgumentException(message);
      }
docs: Validates that the value from {@code map} for the given {@code key} is
  a present and a string. Returns the value when valid; otherwise, throws
  an {@code IllegalArgumentException}, referring to the value as being of
  type{@code} type in the error message.
  @param map a map
  @param key a key
  @param type a type label
  @param <T> the type of value
  @return the string value
  @throws java.util.NoSuchElementException if the required value is not
  present
  @throws java.lang.IllegalArgumentException if the value is in valid