Package javax.json.stream
Class JsonCollectors
- java.lang.Object
-
- javax.json.stream.JsonCollectors
-
public final class JsonCollectors extends Object
This class contains some implementations ofjava.util.stream.Collector
for accumulatingJsonValue
s intoJsonArray
andJsonObject
.- 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.Collector
that implements a "group by" operation on the inputJsonValue
elements.static <T extends JsonArrayBuilder>
Collector<JsonValue,Map<String,T>,JsonObject>groupingBy(Function<JsonValue,String> classifier, Collector<JsonValue,T,JsonArray> downstream)
Constructs ajava.util.stream.Collector
that implements a "group by" operation on the inputJsonValue
elements.static Collector<JsonValue,JsonArrayBuilder,JsonArray>
toJsonArray()
Constructs ajava.util.stream.Collector
that accumulates the inputJsonValue
elements into aJsonArray
.static Collector<Map.Entry<String,JsonValue>,JsonObjectBuilder,JsonObject>
toJsonObject()
Constructs ajava.util.stream.Collector
that 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.Collector
that accumulates the inputJsonValue
elements into aJsonObject
.
-
-
-
Method Detail
-
toJsonArray
public static Collector<JsonValue,JsonArrayBuilder,JsonArray> toJsonArray()
Constructs ajava.util.stream.Collector
that accumulates the inputJsonValue
elements into aJsonArray
.- Returns:
- the constructed Collector
-
toJsonObject
public static Collector<Map.Entry<String,JsonValue>,JsonObjectBuilder,JsonObject> 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,JsonObject> toJsonObject(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,T>,JsonObject> groupingBy(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,JsonArrayBuilder>,JsonObject> groupingBy(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
-
-