jakartaee / jakartaee/jsonp-api

Additional cast methods for `JsonValue`

Open
#401 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
160
Forks
64
Avg merge
4d 5h
Merged PRs (30d)
4

Description

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:
```java
JsonObject obj = ...;
String target = ((JsonString) obj.getValue("/some/path/0/to/my/string")).getString();
```

It would be _slightly_ nicer for the following:
```java
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.

Contributor guide

Open the contributing guide

Research direction

Start with the JsonValue interface and its existing asJsonObject and asJsonArray methods, then inspect the JsonString, JsonNumber, JsonBoolean, and ValueType APIs referenced by the issue. The work is done when the proposed cast methods and any NULL-default overloads are consistently defined and covered by the relevant project tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.