We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The current signature of the collector JsonCollectors#toJsonObject() is:
JsonCollectors#toJsonObject()
static Collector<Map.Entry<String, JsonValue>, JsonObjectBuilder, JsonObject> toJsonObject()
That signature forces the following code:
Map<String, JsonArray> map = ...; JsonObject obj = map.entrySet() .stream() .collect(toJsonObject());
To create another Map.Entry just to cast the value to JsonValue in order to work:
Map.Entry
JsonValue
Map<String, JsonArray> map = ...; JsonObject obj = map.entrySet() .stream() .map(e -> Map.entry(e.getKey(), (JsonValue) e.getValue())) .collect(toJsonObject());
My suggestion is to change the signature of JsonCollectors#toJsonObject() to:
static Collector<Map.Entry<String, ? extends JsonValue>, JsonObjectBuilder, JsonObject> toJsonObject()
So Map of String to any JsonValue sub-type could be collected to JsonObject with little effort.
Map
String
JsonObject
And I guess that modification should be applied to the other signatures that have JsonValue on the receiving side as well:
static Collector<? extends JsonValue, Map<String, JsonArrayBuilder>, JsonObject> groupingBy(Function<? extends JsonValue, String> classifier) static <T extends JsonArrayBuilder> Collector<? extends JsonValue, Map<String, T>, JsonObject> groupingBy(Function<? extends JsonValue, String> classifier, Collector<? extends JsonValue, T, JsonArray> downstream) static Collector<? extends JsonValue, JsonArrayBuilder, JsonArray> toJsonArray() static Collector<? extends JsonValue, JsonObjectBuilder, JsonObject> toJsonObject(Function<? extends JsonValue, String> keyMapper, Function<? extends JsonValue, JsonValue> valueMapper)
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The current signature of the collector
JsonCollectors#toJsonObject()
is:That signature forces the following code:
To create another
Map.Entry
just to cast the value toJsonValue
in order to work:My suggestion is to change the signature of
JsonCollectors#toJsonObject()
to:So
Map
ofString
to anyJsonValue
sub-type could be collected toJsonObject
with little effort.And I guess that modification should be applied to the other signatures that have
JsonValue
on the receiving side as well:The text was updated successfully, but these errors were encountered: