Support Optional in UriComponentsBuilder#queryParam
Closes gh-25951
This commit is contained in:
@@ -698,7 +698,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
|
||||
Assert.notNull(name, "Name must not be null");
|
||||
if (!ObjectUtils.isEmpty(values)) {
|
||||
for (Object value : values) {
|
||||
String valueAsString = (value != null ? value.toString() : null);
|
||||
String valueAsString = getQueryParamValue(value);
|
||||
this.queryParams.add(name, valueAsString);
|
||||
}
|
||||
}
|
||||
@@ -709,6 +709,16 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String getQueryParamValue(@Nullable Object value) {
|
||||
if (value != null) {
|
||||
return (value instanceof Optional ?
|
||||
((Optional<?>) value).map(Object::toString).orElse(null) :
|
||||
value.toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UriComponentsBuilder queryParam(String name, @Nullable Collection<?> values) {
|
||||
return queryParam(name, (CollectionUtils.isEmpty(values) ? EMPTY_VALUES : values.toArray()));
|
||||
|
||||
Reference in New Issue
Block a user