Package jakarta.json.stream
Class JsonCollectors
- java.lang.Object
-
- jakarta.json.stream.JsonCollectors
-
public final class JsonCollectors extends Object
This class contains some implementations ofjava.util.stream.Collectorfor accumulatingJsonValues intoJsonArrayandJsonObject.- Since:
- 1.1
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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>groupingBy(Function<JsonValue,String> classifier, Collector<JsonValue,T,JsonArray> downstream)Constructs ajava.util.stream.Collectorthat implements a "group by" operation on the inputJsonValueelements.static Collector<JsonValue,JsonArrayBuilder,JsonArray>toJsonArray()Constructs ajava.util.stream.Collectorthat accumulates the inputJsonValueelements into aJsonArray.static Collector<Map.Entry<String,JsonValue>,JsonObjectBuilder,JsonObject>toJsonObject()Constructs ajava.util.stream.Collectorthat accumulates the inputMap.Entry<String,JsonValue>elements into aJsonObject.static Collector<JsonValue,JsonObjectBuilder,JsonObject>toJsonObject(Function<JsonValue,String> keyMapper, Function<JsonValue,JsonValue> valueMapper)Constructs ajava.util.stream.Collectorthat accumulates the inputJsonValueelements into aJsonObject.
-
-
-
Method Detail
-
toJsonArray
public static Collector<JsonValue,JsonArrayBuilder,JsonArray> toJsonArray()
Constructs ajava.util.stream.Collectorthat accumulates the inputJsonValueelements into aJsonArray.- Returns:
- the constructed Collector
-
toJsonObject
public static Collector<Map.Entry<String,JsonValue>,JsonObjectBuilder,JsonObject> 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,JsonObject> toJsonObject(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,T>,JsonObject> groupingBy(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,JsonArrayBuilder>,JsonObject> groupingBy(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
-
-