The earlier definition of replaceQueryParam(String name, Object... values)
didn't remove the query param if the passed value is null. So, replaceQueryParam("param1" , null)
would still lead to presence of queryparam param1
in the URI.
So if value is null, one would need to write this piece of code:
if(value== null) {
replaceQueryParam("param1");
} else {
replaceQueryParam("param1", value);
}
Hence added a new definition of the function which takes in a single argument Object value
.
Comment From: snicoll
I wonder if we shouldn't update the check in the vararg case, rather than introducing a new method. WDYT @rstoyanchev ?
Comment From: rstoyanchev
Thank you for the suggestion. However, the proposed change would break existing applications which rely on the present behavior. Moreover the current behavior is by design where both the queryParam
and replaceQueryParam
methods and their overloaded variants, treat null
as a query parameter without a value. This aligns with similar behavior in the Servlet API on the server side where a query parameter may be present with or without a value, or not present at all. So, yes if you want to remove a parameter completely, you will need such conditional logic.