jakartaee / jakartaee/rest

resolveTemplates should ignore null values

Open
#768 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
400
Forks
143
PR merge metrics
No merged PRs in 30d

Description

Null values are allowed within query params. Jax-Rs ignores null values by leaving the query string:

```
httpClient.target(BASE_URL).queryParam("test", null).queryParam("user", 1);
-> BASE_URL?user=1
```
```

httpClient.target(BASE_URL).queryParam("test", "ok").queryParam("user", 1);
-> BASE_URL?test=ok&user=1
```

This is well done. However, when using the "resolveTemplate" with a template uri, null values are not allowed:

```
Map map = new HashMap<>();
map.put("test", null);
map.put("user" 1);
String path = BASE_URL + "?test={test}&user={user}";
var target = httpClient.target(path).resolveTemplates(map);
```
-> throws Null pointer exception, instead of using "BASE_URL?user=1" if query param "test" is null.

A new method `javax.ws.rs.client.WebTarget.resolveTemplates(Map templateValues, boolean ignoreNullParams)` can be used to get the following behaviour:

If any query param is `null` and `ignoreNullParams = true`, then jaxrs should also ignore the template param with null (like `.queryParam("test", null)`) and construct the url by leaving the `null` param, instead of throwing Null pointer exception.

Contributor guide

Open the contributing guide

Research direction

Start by locating WebTarget.resolveTemplates and the existing query-parameter handling. Add the proposed overload with ignoreNullParams behavior, preserving non-null template parameters while omitting null query parameters, and verify the examples in the issue without throwing a NullPointerException.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.