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
JsonValue
s 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.Collector
that implements a "group by" operation on the inputJsonValue
elements.static <T extends JsonArrayBuilder>
Collector<JsonValue,Map<String, T>, JsonObject> Constructs ajava.util.stream.Collector
that implements a "group by" operation on the inputJsonValue
elements.static Collector<JsonValue,
JsonArrayBuilder, JsonArray> Constructs ajava.util.stream.Collector
that accumulates the inputJsonValue
elements into aJsonArray
.Constructs ajava.util.stream.Collector
that accumulates the inputMap.Entry<String,JsonValue>
elements into aJsonObject
.Constructs ajava.util.stream.Collector
that accumulates the inputJsonValue
elements into aJsonObject
.
-
Method Details
-
toJsonArray
Constructs ajava.util.stream.Collector
that accumulates the inputJsonValue
elements into aJsonArray
.- Returns:
- the constructed Collector
-
toJsonObject
Constructs ajava.util.stream.Collector
that 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.Collector
that accumulates the inputJsonValue
elements into aJsonObject
. The name/value pairs of theJsonObject
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, groupingByT>, JsonObject> (Function<JsonValue, String> classifier, Collector<JsonValue, T, JsonArray> downstream) Constructs ajava.util.stream.Collector
that implements a "group by" operation on the inputJsonValue
elements. A classifier function maps the inputJsonValue
s to keys, and theJsonValue
s are partitioned into groups according to the value of the key. A reduction operation is performed on theJsonValue
s 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 accumulationJsonArrayBuilder
of the downstream collector- Parameters:
classifier
- a function mapping the inputJsonValue
s to a String, producing keysdownstream
- aCollector
that implements a reduction operation on theJsonValue
s in each group.- Returns:
- the constructed
Collector
-
groupingBy
public static Collector<JsonValue,Map<String, groupingByJsonArrayBuilder>, JsonObject> (Function<JsonValue, String> classifier) Constructs ajava.util.stream.Collector
that implements a "group by" operation on the inputJsonValue
elements. A classifier function maps the inputJsonValue
s to keys, and theJsonValue
s are partitioned into groups according to the value of the key. TheJsonValue
s in each group are added to aJsonArray
. The key and theJsonArray
in each group becomes the name/value pair of the resultantJsonObject
.- Parameters:
classifier
- a function mapping the inputJsonValue
s to a String, producing keys- Returns:
- the constructed
Collector
-