You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Makes traversing generic JsonObject and JsonArray objects faster and easier.
Feature description
I'd like to add convenience methods to JsonArray and JsonObject, so that each has methods based on their respective get to directly get each type (int, double, boolean, etc.), rather than having to go through a JsonElement first.
For example, consider the following scenario: I want to retrieve the "name" property of the third employee.
currently, with a generic JsonObject, it would look something like this:
JsonObject obj;
String name = obj.get("employees").getAsJsonArray()
.get(2).getAsJsonObject()
.get("name").getAsString();
versus with my fork, which would allow the following as an alternative:
JsonObject obj;
String name = obj.getJsonArray("employees")
.getJsonObject(2)
.getString("name");
Alternatives / workarounds
The alternative is described above in my example.
One final note, I'm more than willing to (and have began to) implement these convenience methods myself; I just want to make sure this is a welcome change before I create and document all of them in a new fork.
Thank you!
The text was updated successfully, but these errors were encountered:
It would cause API bloating: this would require the entire get***(name) and is***(name) method family to be replicated in JsonObject and get***(index) and is***(index) to be replicated in JsonArray respectively. Having .get(name)/.get(index) is simpler to design and guarantees that you can always access whole JsonElement API not worrying that some APIs are not replicated to JsonObject or JsonArray.
The JsonElement hierarchy is probably the clunkiest part of the Gson API, but if we double the size of JsonObject with new methods then it will still be clunky but even more confusing than it is today.
Problem solved by the feature
Makes traversing generic
JsonObject
andJsonArray
objects faster and easier.Feature description
I'd like to add convenience methods to
JsonArray
andJsonObject
, so that each has methods based on their respectiveget
to directly get each type (int, double, boolean, etc.), rather than having to go through aJsonElement
first.For example, consider the following scenario: I want to retrieve the "name" property of the third employee.
currently, with a generic
JsonObject
, it would look something like this:versus with my fork, which would allow the following as an alternative:
Alternatives / workarounds
The alternative is described above in my example.
One final note, I'm more than willing to (and have began to) implement these convenience methods myself; I just want to make sure this is a welcome change before I create and document all of them in a new fork.
Thank you!
The text was updated successfully, but these errors were encountered: