Closed glassfishrobot closed 7 years ago
Reported by kratz
kratz said: Diff to be applied on JSON-P master:
diff --git a/api/src/main/java/javax/json/stream/JsonCollectors.java b/api/src/main/java/javax/json/stream/JsonCollectors.java
index b6db550..0ccfaf8 100644
--- a/api/src/main/java/javax/json/stream/JsonCollectors.java
+++ b/api/src/main/java/javax/json/stream/JsonCollectors.java
@@ -82,6 +82,19 @@ public final class JsonCollectors {
}
/**
+ * Constructs a {@code java.util.stream.Collector} that accumulates the input {@code Map.Entry<String,JsonValue>}
+ * elements into a {@code JsonObject}.
+ * @return the constructed Collector
+ */
+ public static Collector<Map.Entry<String,JsonValue>, JsonObjectBuilder, JsonObject> toJsonObject() {
+ return Collector.of(
+Json::createObjectBuilder,
+(JsonObjectBuilder b, Map.Entry<String,JsonValue> v) -> b.add(v.getKey(), v.getValue()),
+JsonObjectBuilder::addAll,
+JsonObjectBuilder::build);
+ }
+
+ /**
* Constructs a {@code java.util.stream.Collector} that accumulates the input {@code JsonValue}
* elements into a {@code JsonObject}. The name/value pairs of the {@code JsonObject} are computed
* by applying the provided mapping functions.
Edit: There is no need to modify JsonObject because this interface extends Map and entrySet().stream() is enough to open the stream of Map.Entry<String,JsonValue>.
kratz said: Also new toJsonObject() is counterpart to JsonParser#getObjectStream() the same way as toJsonArray() method is for JsonParser#getArrayStream(). Using those collectors with JsonParser is another use-case for API changes introduced in #68 and this task.
Anither question is, whether it would look better to hide Map.Entry<String,JsonValue> behind some better identifier (interface), e.g. ObjectValueMapping.
This issue was imported from java.net JIRA JSON_PROCESSING_SPEC-82
Marked as fixed on Monday, January 30th 2017, 8:29:42 am
68 introduced simple API for JSON array queries. It would be nice to add the same functionality for JSON object.
Affected Versions
[1.1]