Package jakarta.json.stream
Class JsonCollectors
java.lang.Object
jakarta.json.stream.JsonCollectors
This class contains some implementations of
java.util.stream.Collector for accumulating
JsonValues into JsonArray and JsonObject.- Since:
- 1.1
-
Method Summary
Modifier and TypeMethodDescriptionstatic Collector<JsonValue,Map<String, JsonArrayBuilder>, JsonObject> groupingBy(Function<JsonValue, String> classifier) Constructs ajava.util.stream.Collectorthat implements a "group by" operation on the inputJsonValueelements.static <T extends JsonArrayBuilder>
Collector<JsonValue,Map<String, T>, JsonObject> Constructs ajava.util.stream.Collectorthat implements a "group by" operation on the inputJsonValueelements.static Collector<JsonValue,JsonArrayBuilder, JsonArray> Constructs ajava.util.stream.Collectorthat accumulates the inputJsonValueelements into aJsonArray.Constructs ajava.util.stream.Collectorthat accumulates the inputMap.Entry<String,JsonValue>elements into aJsonObject.Constructs ajava.util.stream.Collectorthat accumulates the inputJsonValueelements into aJsonObject.
-
Method Details
-
toJsonArray
Constructs ajava.util.stream.Collectorthat accumulates the inputJsonValueelements into aJsonArray.- Returns:
- the constructed Collector
-
toJsonObject
Constructs ajava.util.stream.Collectorthat accumulates the inputMap.Entry<String,JsonValue>elements into aJsonObject.- Returns:
- the constructed Collector
-
toJsonObject
public static Collector<JsonValue,JsonObjectBuilder, toJsonObjectJsonObject> (Function<JsonValue, String> keyMapper, Function<JsonValue, JsonValue> valueMapper) Constructs ajava.util.stream.Collectorthat accumulates the inputJsonValueelements into aJsonObject. The name/value pairs of theJsonObjectare 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, groupingByT>, JsonObject> (Function<JsonValue, String> classifier, Collector<JsonValue, T, JsonArray> downstream) Constructs ajava.util.stream.Collectorthat implements a "group by" operation on the inputJsonValueelements. A classifier function maps the inputJsonValues to keys, and theJsonValues are partitioned into groups according to the value of the key. A reduction operation is performed on theJsonValues in each group, using the downstreamCollector. For each group, the key and the results of the reduction operation become the name/value pairs of the resultantJsonObject.- Type Parameters:
T- the intermediate accumulationJsonArrayBuilderof the downstream collector- Parameters:
classifier- a function mapping the inputJsonValues to a String, producing keysdownstream- aCollectorthat implements a reduction operation on theJsonValues in each group.- Returns:
- the constructed
Collector
-
groupingBy
public static Collector<JsonValue,Map<String, groupingByJsonArrayBuilder>, JsonObject> (Function<JsonValue, String> classifier) Constructs ajava.util.stream.Collectorthat implements a "group by" operation on the inputJsonValueelements. A classifier function maps the inputJsonValues to keys, and theJsonValues are partitioned into groups according to the value of the key. TheJsonValues in each group are added to aJsonArray. The key and theJsonArrayin each group becomes the name/value pair of the resultantJsonObject.- Parameters:
classifier- a function mapping the inputJsonValues to a String, producing keys- Returns:
- the constructed
Collector
-