jakartaee / jsonp-api

Jakarta JSON Processing
https://eclipse.org/ee4j/jsonp
Other
138 stars 59 forks source link

Additional cast methods for `JsonValue` #401

Open MikeEdgar opened 11 months ago

MikeEdgar commented 11 months ago

As of 1.1, the JsonValue interface provides convenience methods to cast the value to JsonObject and JsonArray. Is there a reason to limit things to those two cases?

Currently, the approach to get a value via a pointer looks like:

JsonObject obj = ...;
String target = ((JsonString) obj.getValue("/some/path/0/to/my/string")).getString();

It would be slightly nicer for the following:

JsonObject obj = ...;
String target = obj.getValue("/some/path/0/to/my/string").asJsonString().getString();

Similarly, methods for asJsonNumber and asJsonBoolean, perhaps with overloads that tolerate the ValueType of NULL with a default argument.