src/main/java/org/apache/hadoop/hdfs/server/namenode/analytics/Helper.java
public static void toJsonList(HttpServletResponse resp, Enum[]... values) throws IOException {
    JsonGenerator json =
        new JsonFactory().createJsonGenerator(resp.getWriter()).useDefaultPrettyPrinter();
    try {
      json.writeStartObject();
      for (int i = 0; i < values.length; i++) {
        Enum[] enumList = values[i];
        json.writeArrayFieldStart("Possibilities " + (i + 1));
        for (Enum value : enumList) {
          if (value != null) {
            json.writeStartObject();
            json.writeStringField("Name", value.name());
            json.writeEndObject();
          }
        }
        json.writeEndArray();
      }
      json.writeEndObject();
    } finally {
      IOUtils.closeStream(json);
    }
  }
/**
   * Write a set of enums out to HTTP Response as a JSON list.
   *
   * @param resp the http response
   * @param values the enums
   * @throws IOException if parsing or writing fails
   */
Write a set of enums out to HTTP Response as a JSON list.
@param resp the http response
@param values the enums
@throws IOException if parsing or writing fails
Write a set of enums out to HTTP Response as a JSON list . @param resp the http response @param values the enums @throws IOException if parsing or writing fails
public static void toJsonList(HttpServletResponse resp, Enum[]... values) throws IOException {
    JsonGenerator json =
        new JsonFactory().createJsonGenerator(resp.getWriter()).useDefaultPrettyPrinter();
    try {
      json.writeStartObject();
      for (int i = 0; i < values.length; i++) {
        Enum[] enumList = values[i];
        json.writeArrayFieldStart("Possibilities " + (i + 1));
        for (Enum value : enumList) {
          if (value != null) {
            json.writeStartObject();
            json.writeStringField("Name", value.name());
            json.writeEndObject();
          }
        }
        json.writeEndArray();
      }
      json.writeEndObject();
    } finally {
      IOUtils.closeStream(json);
    }
  }
public static void toJsonList ( HttpServletResponse resp , Enum [ ] ... values ) throws IOException { JsonGenerator json = new JsonFactory ( ) . createJsonGenerator ( resp . getWriter ( ) ) . useDefaultPrettyPrinter ( ) ; try { json . writeStartObject ( ) ; for ( int i = 0 ; i < values . length ; i ++ ) { Enum [ ] enumList = values [ i ] ; json . writeArrayFieldStart ( "Possibilities " + ( i + 1 ) ) ; for ( Enum value : enumList ) { if ( value != null ) { json . writeStartObject ( ) ; json . writeStringField ( "Name" , value . name ( ) ) ; json . writeEndObject ( ) ; } } json . writeEndArray ( ) ; } json . writeEndObject ( ) ; } finally { IOUtils . closeStream ( json ) ; } }
Write a set of enums out to HTTP Response as a JSON list.
Write a set of enums out to HTTP Response as a JSON list .