Class JsonCollectors

java.lang.Object
jakarta.json.stream.JsonCollectors

public final class JsonCollectors extends Object
This class contains some implementations of java.util.stream.Collector for accumulating JsonValues into JsonArray and JsonObject.
Since:
1.1
  • Method Details

    • toJsonArray

      public static Collector<JsonValue,JsonArrayBuilder,JsonArray> toJsonArray()
      Constructs a java.util.stream.Collector that accumulates the input JsonValue elements into a JsonArray.
      Returns:
      the constructed Collector
    • toJsonObject

      Constructs a java.util.stream.Collector that accumulates the input Map.Entry<String,JsonValue> elements into a JsonObject.
      Returns:
      the constructed Collector
    • toJsonObject

      public static Collector<JsonValue,JsonObjectBuilder,JsonObject> toJsonObject(Function<JsonValue,String> keyMapper, Function<JsonValue,JsonValue> valueMapper)
      Constructs a java.util.stream.Collector that accumulates the input JsonValue elements into a JsonObject. The name/value pairs of the JsonObject are computed by applying the provided mapping functions.
      Parameters:
      keyMapper - a mapping function to produce names.
      valueMapper - a mapping function to produce values
      Returns:
      the constructed Collector
    • groupingBy

      public static <T extends JsonArrayBuilder> Collector<JsonValue,Map<String,T>,JsonObject> groupingBy(Function<JsonValue,String> classifier, Collector<JsonValue,T,JsonArray> downstream)
      Constructs a java.util.stream.Collector that implements a "group by" operation on the input JsonValue elements. A classifier function maps the input JsonValues to keys, and the JsonValues are partitioned into groups according to the value of the key. A reduction operation is performed on the JsonValues in each group, using the downstream Collector. For each group, the key and the results of the reduction operation become the name/value pairs of the resultant JsonObject.
      Type Parameters:
      T - the intermediate accumulation JsonArrayBuilder of the downstream collector
      Parameters:
      classifier - a function mapping the input JsonValues to a String, producing keys
      downstream - a Collector that implements a reduction operation on the JsonValues in each group.
      Returns:
      the constructed Collector
    • groupingBy

      public static Collector<JsonValue,Map<String,JsonArrayBuilder>,JsonObject> groupingBy(Function<JsonValue,String> classifier)
      Constructs a java.util.stream.Collector that implements a "group by" operation on the input JsonValue elements. A classifier function maps the input JsonValues to keys, and the JsonValues are partitioned into groups according to the value of the key. The JsonValues in each group are added to a JsonArray. The key and the JsonArray in each group becomes the name/value pair of the resultant JsonObject.
      Parameters:
      classifier - a function mapping the input JsonValues to a String, producing keys
      Returns:
      the constructed Collector