Repository: open-telemetry/opentelemetry-java
File: exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/Otel2PrometheusConverter.java (Java)

Code before:
    return new MetricMetadata(name, help, unit);
  }

  private static String typeString(MetricSnapshot snapshot) {
    // Simple helper for a log message.
    return snapshot.getClass().getSimpleName().replace("Snapshot", "").toLowerCase(Locale.ENGLISH);
  }

  private static String toLabelValue(AttributeType type, Object attributeValue) {
    switch (type) {
      case STRING:
      case BOOLEAN:
      case LONG:
      case DOUBLE:
        return attributeValue.toString();
      case BOOLEAN_ARRAY:
      case LONG_ARRAY:
      case DOUBLE_ARRAY:
      case STRING_ARRAY:
        if (attributeValue instanceof List) {
          return ((List<?>) attributeValue)
              .stream()
                  .map(String::valueOf)
                  .map(it -> AttributeType.STRING_ARRAY.equals(type) ? toJsonValidStr(it) : it)
                  .collect(Collectors.toList())
                  .toString();
        } else {
          LOGGER.log(
              Level.WARNING,
              "Unexpected label value of {0} for {1}, toString() is being used as fallback value...",
              new Object[] {attributeValue.getClass(), type.name()});
          return attributeValue.toString();
        }
    }
    throw new IllegalStateException("Unrecognized AttributeType: " + type);
  }

  public static String toJsonValidStr(String str) {
    StringBuilder sb = new StringBuilder();
    sb.append('"');
    for (int i = 0; i < str.length(); i++) {
      char c = str.charAt(i);

      switch (c) {
        case '"':
          sb.append("\\\"");
          break;
        case '\\':
          sb.append("\\\\");
          break;
        case '\b':

Review comment (suggestion):
Its strange to rely on the `List#toString()` having the same format as a JSON array. Also, using the stream API like this allocates more memory than is needed. How about something like:

```
  @SuppressWarnings("unchecked")
  private static String toLabelValue(AttributeType type, Object attributeValue) {
    switch (type) {
      case STRING:
      case BOOLEAN:
      case LONG:
      case DOUBLE:
        return attributeValue.toString();
      case BOOLEAN_ARRAY:
      case LONG_ARRAY:
      case DOUBLE_ARRAY:
      case STRING_ARRAY:
        return toJsonString((List<Object>) attributeValue);
    }
    throw new IllegalStateException("Unrecognized AttributeType: " + type);
  }

  public static String toJsonString(List<Object> values) {
    StringJoiner joiner = new StringJoiner(",", "[", "]");
    for (int i = 0; i < values.size(); i++) {
      Object value = values.get(i);
      joiner.add(value instanceof String ? toJsonValidStr((String) value) : String.valueOf(value));
    }
    return joiner.toString();
  }
```


Code after:
    }
    return new MetricMetadata(name, help, unit);
  }

  private static String typeString(MetricSnapshot snapshot) {
    // Simple helper for a log message.
    return snapshot.getClass().getSimpleName().replace("Snapshot", "").toLowerCase(Locale.ENGLISH);
  }

  private static String toLabelValue(AttributeType type, Object attributeValue) {
    switch (type) {
      case STRING:
      case BOOLEAN:
      case LONG:
      case DOUBLE:
        return attributeValue.toString();
      case BOOLEAN_ARRAY:
      case LONG_ARRAY:
      case DOUBLE_ARRAY:
      case STRING_ARRAY:
        if (attributeValue instanceof List) {
          return toJsonStr((List<?>) attributeValue);
        } else {
          throw new IllegalStateException(
              String.format(
                  "Unexpected label value of %s for %s",
                  attributeValue.getClass().getName(), type.name()));
        }
    }
    throw new IllegalStateException("Unrecognized AttributeType: " + type);
  }

  public static String toJsonStr(List<?> attributeValue) {
    StringJoiner joiner = new StringJoiner(",", "[", "]");
    for (int i = 0; i < attributeValue.size(); i++) {
      Object value = attributeValue.get(i);
      joiner.add(value instanceof String ? toJsonValidStr((String) value) : String.valueOf(value));
    }
    return joiner.toString();
  }

  public static String toJsonValidStr(String str) {
    StringBuilder sb = new StringBuilder();
    sb.append('"');
    for (int i = 0; i < str.length(); i++) {
      char c = str.charAt(i);

      switch (c) {
        case '"':
          sb.append("\\\"");
          break;