jakartaee / jakartaee/jsonp-api
Improvement to JsonCollectors interface
- Dominant language
- Java
- Stars
- 160
- Forks
- 64
- Avg merge
- 4d 5h
- Merged PRs (30d)
- 4
Description
The current signature of the collector ```JsonCollectors#toJsonObject()``` is:
```java
static Collector, JsonObjectBuilder, JsonObject> toJsonObject()
```
That signature forces the following code:
```java
Map map = ...;
JsonObject obj = map.entrySet()
.stream()
.collect(toJsonObject());
```
To create another ```Map.Entry``` just to cast the value to ```JsonValue``` in order to work:
```java
Map 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:
```java
static Collector, JsonObjectBuilder, JsonObject> toJsonObject()
```
So ```Map``` of ```String``` to any ```JsonValue``` sub-type could be collected to ```JsonObject``` with little effort.
And I guess that modification should be applied to the other signatures that have ```JsonValue``` on the receiving side as well:
```java
static Collector, JsonObject>
groupingBy(Function classifier)
static
Collector, JsonObject>
groupingBy(Function classifier, Collector downstream)
static Collector toJsonArray()
static Collector
toJsonObject(Function keyMapper, Function valueMapper)
```
Contributor guide
Research direction
Start with the JsonCollectors#toJsonObject() signature and compare the other listed collectors that receive JsonValue. Check how their generic bounds affect subtype-valued maps and streams, then verify that all proposed signatures compile and preserve existing collector behavior. Done means subtype values can be collected without creating and casting Map.Entry instances.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100