Description
The API should offer abstract implementations for both JsonObject
and JsonArray
. These implementations will encapsluate a JsonObject
and JsonArray
delegator respectively , in order to leverage polymorphism.
E.g.
public abstract class AbstractJsonObject implements JsonObject {
private final JsonObject delegate;
public AbstractJsonObject (final JsonObject delegate) {
this.delegate = delegate;
}
@Override
public final JsonArray getJsonArray(final String name) {
return this.delegate.getJsonArray(name);
}
//all other implementations, all delegated
}
Here are some examples of usage (object orientation):
Polymorphic entity: https://github.com/amihaiemil/docker-java-api/blob/master/src/main/java/com/amihaiemil/docker/RtImage.java (extends JsonResource which is the same concept).
2 Articles:
https://www.amihaiemil.com/2017/10/16/javaee8-jsoncollectors-oop-alternative.html
https://www.amihaiemil.com/2017/06/14/non-flushable-jsonobjectbuilder.html (this is for JsonObjectBuilder)
This should be an API addition, obviously, since these classes are provider-agnostic, they are abstract and do not care about any concrete implementation.
If this is wanted, I'll make a PR myself.