mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Make URI template variables nullable
Closes gh-34221
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -304,7 +304,7 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
* @return the created builder
|
||||
* @since 5.3
|
||||
*/
|
||||
public static BodyBuilder method(HttpMethod method, String uriTemplate, Object... uriVariables) {
|
||||
public static BodyBuilder method(HttpMethod method, String uriTemplate, @Nullable Object... uriVariables) {
|
||||
return new DefaultBodyBuilder(method, uriTemplate, uriVariables);
|
||||
}
|
||||
|
||||
@@ -336,7 +336,7 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
* @return the created builder
|
||||
* @since 5.3
|
||||
*/
|
||||
public static HeadersBuilder<?> get(String uriTemplate, Object... uriVariables) {
|
||||
public static HeadersBuilder<?> get(String uriTemplate, @Nullable Object... uriVariables) {
|
||||
return method(HttpMethod.GET, uriTemplate, uriVariables);
|
||||
}
|
||||
|
||||
@@ -356,7 +356,7 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
* @return the created builder
|
||||
* @since 5.3
|
||||
*/
|
||||
public static HeadersBuilder<?> head(String uriTemplate, Object... uriVariables) {
|
||||
public static HeadersBuilder<?> head(String uriTemplate, @Nullable Object... uriVariables) {
|
||||
return method(HttpMethod.HEAD, uriTemplate, uriVariables);
|
||||
}
|
||||
|
||||
@@ -376,7 +376,7 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
* @return the created builder
|
||||
* @since 5.3
|
||||
*/
|
||||
public static BodyBuilder post(String uriTemplate, Object... uriVariables) {
|
||||
public static BodyBuilder post(String uriTemplate, @Nullable Object... uriVariables) {
|
||||
return method(HttpMethod.POST, uriTemplate, uriVariables);
|
||||
}
|
||||
|
||||
@@ -396,7 +396,7 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
* @return the created builder
|
||||
* @since 5.3
|
||||
*/
|
||||
public static BodyBuilder put(String uriTemplate, Object... uriVariables) {
|
||||
public static BodyBuilder put(String uriTemplate, @Nullable Object... uriVariables) {
|
||||
return method(HttpMethod.PUT, uriTemplate, uriVariables);
|
||||
}
|
||||
|
||||
@@ -416,7 +416,7 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
* @return the created builder
|
||||
* @since 5.3
|
||||
*/
|
||||
public static BodyBuilder patch(String uriTemplate, Object... uriVariables) {
|
||||
public static BodyBuilder patch(String uriTemplate, @Nullable Object... uriVariables) {
|
||||
return method(HttpMethod.PATCH, uriTemplate, uriVariables);
|
||||
}
|
||||
|
||||
@@ -436,7 +436,7 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
* @return the created builder
|
||||
* @since 5.3
|
||||
*/
|
||||
public static HeadersBuilder<?> delete(String uriTemplate, Object... uriVariables) {
|
||||
public static HeadersBuilder<?> delete(String uriTemplate, @Nullable Object... uriVariables) {
|
||||
return method(HttpMethod.DELETE, uriTemplate, uriVariables);
|
||||
}
|
||||
|
||||
@@ -456,7 +456,7 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
* @return the created builder
|
||||
* @since 5.3
|
||||
*/
|
||||
public static HeadersBuilder<?> options(String uriTemplate, Object... uriVariables) {
|
||||
public static HeadersBuilder<?> options(String uriTemplate, @Nullable Object... uriVariables) {
|
||||
return method(HttpMethod.OPTIONS, uriTemplate, uriVariables);
|
||||
}
|
||||
|
||||
@@ -601,9 +601,9 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
|
||||
private final @Nullable String uriTemplate;
|
||||
|
||||
private final Object @Nullable [] uriVarsArray;
|
||||
private final @Nullable Object @Nullable [] uriVarsArray;
|
||||
|
||||
private final @Nullable Map<String, ?> uriVarsMap;
|
||||
private final @Nullable Map<String, ? extends @Nullable Object> uriVarsMap;
|
||||
|
||||
DefaultBodyBuilder(HttpMethod method, URI url) {
|
||||
this.method = method;
|
||||
@@ -613,7 +613,7 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
this.uriVarsMap = null;
|
||||
}
|
||||
|
||||
DefaultBodyBuilder(HttpMethod method, String uriTemplate, Object... uriVars) {
|
||||
DefaultBodyBuilder(HttpMethod method, String uriTemplate, @Nullable Object... uriVars) {
|
||||
this.method = method;
|
||||
this.uri = null;
|
||||
this.uriTemplate = uriTemplate;
|
||||
@@ -621,7 +621,7 @@ public class RequestEntity<T> extends HttpEntity<T> {
|
||||
this.uriVarsMap = null;
|
||||
}
|
||||
|
||||
DefaultBodyBuilder(HttpMethod method, String uriTemplate, Map<String, ?> uriVars) {
|
||||
DefaultBodyBuilder(HttpMethod method, String uriTemplate, Map<String, ? extends @Nullable Object> uriVars) {
|
||||
this.method = method;
|
||||
this.uri = null;
|
||||
this.uriTemplate = uriTemplate;
|
||||
|
||||
@@ -305,7 +305,7 @@ final class DefaultRestClient implements RestClient {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestBodySpec uri(String uriTemplate, Object... uriVariables) {
|
||||
public RequestBodySpec uri(String uriTemplate, @Nullable Object... uriVariables) {
|
||||
UriBuilder uriBuilder = uriBuilderFactory.uriString(uriTemplate);
|
||||
attribute(URI_TEMPLATE_ATTRIBUTE, uriBuilder.toUriString());
|
||||
return uri(DefaultRestClient.this.uriBuilderFactory.expand(uriTemplate, uriVariables));
|
||||
|
||||
@@ -503,14 +503,14 @@ public interface RestClient {
|
||||
* <p>If a {@link UriBuilderFactory} was configured for the client (for example,
|
||||
* with a base URI) it will be used to expand the URI template.
|
||||
*/
|
||||
S uri(String uri, Object... uriVariables);
|
||||
S uri(String uri, @Nullable Object... uriVariables);
|
||||
|
||||
/**
|
||||
* Specify the URI for the request using a URI template and URI variables.
|
||||
* <p>If a {@link UriBuilderFactory} was configured for the client (for example,
|
||||
* with a base URI) it will be used to expand the URI template.
|
||||
*/
|
||||
S uri(String uri, Map<String, ?> uriVariables);
|
||||
S uri(String uri, Map<String, ? extends @Nullable Object> uriVariables);
|
||||
|
||||
/**
|
||||
* Specify the URI starting with a URI template and finishing off with a
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -53,7 +53,7 @@ public interface RestOperations {
|
||||
* @param uriVariables the variables to expand the template
|
||||
* @return the converted object
|
||||
*/
|
||||
<T> @Nullable T getForObject(String url, Class<T> responseType, Object... uriVariables) throws RestClientException;
|
||||
<T> @Nullable T getForObject(String url, Class<T> responseType, @Nullable Object... uriVariables) throws RestClientException;
|
||||
|
||||
/**
|
||||
* Retrieve a representation by doing a GET on the URI template.
|
||||
@@ -64,7 +64,7 @@ public interface RestOperations {
|
||||
* @param uriVariables the map containing variables for the URI template
|
||||
* @return the converted object
|
||||
*/
|
||||
<T> @Nullable T getForObject(String url, Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException;
|
||||
<T> @Nullable T getForObject(String url, Class<T> responseType, Map<String, ? extends @Nullable Object> uriVariables) throws RestClientException;
|
||||
|
||||
/**
|
||||
* Retrieve a representation by doing a GET on the URL.
|
||||
@@ -85,7 +85,7 @@ public interface RestOperations {
|
||||
* @return the entity
|
||||
* @since 3.0.2
|
||||
*/
|
||||
<T> ResponseEntity<T> getForEntity(String url, Class<T> responseType, Object... uriVariables)
|
||||
<T> ResponseEntity<T> getForEntity(String url, Class<T> responseType, @Nullable Object... uriVariables)
|
||||
throws RestClientException;
|
||||
|
||||
/**
|
||||
@@ -98,7 +98,7 @@ public interface RestOperations {
|
||||
* @return the converted object
|
||||
* @since 3.0.2
|
||||
*/
|
||||
<T> ResponseEntity<T> getForEntity(String url, Class<T> responseType, Map<String, ?> uriVariables)
|
||||
<T> ResponseEntity<T> getForEntity(String url, Class<T> responseType, Map<String, ? extends @Nullable Object> uriVariables)
|
||||
throws RestClientException;
|
||||
|
||||
/**
|
||||
@@ -121,7 +121,7 @@ public interface RestOperations {
|
||||
* @param uriVariables the variables to expand the template
|
||||
* @return all HTTP headers of that resource
|
||||
*/
|
||||
HttpHeaders headForHeaders(String url, Object... uriVariables) throws RestClientException;
|
||||
HttpHeaders headForHeaders(String url, @Nullable Object... uriVariables) throws RestClientException;
|
||||
|
||||
/**
|
||||
* Retrieve all headers of the resource specified by the URI template.
|
||||
@@ -130,7 +130,7 @@ public interface RestOperations {
|
||||
* @param uriVariables the map containing variables for the URI template
|
||||
* @return all HTTP headers of that resource
|
||||
*/
|
||||
HttpHeaders headForHeaders(String url, Map<String, ?> uriVariables) throws RestClientException;
|
||||
HttpHeaders headForHeaders(String url, Map<String, ? extends @Nullable Object> uriVariables) throws RestClientException;
|
||||
|
||||
/**
|
||||
* Retrieve all headers of the resource specified by the URL.
|
||||
@@ -159,7 +159,7 @@ public interface RestOperations {
|
||||
* @return the value for the {@code Location} header
|
||||
* @see HttpEntity
|
||||
*/
|
||||
@Nullable URI postForLocation(String url, @Nullable Object request, Object... uriVariables) throws RestClientException;
|
||||
@Nullable URI postForLocation(String url, @Nullable Object request, @Nullable Object... uriVariables) throws RestClientException;
|
||||
|
||||
/**
|
||||
* Create a new resource by POSTing the given object to the URI template, and return the value of
|
||||
@@ -178,7 +178,7 @@ public interface RestOperations {
|
||||
* @return the value for the {@code Location} header
|
||||
* @see HttpEntity
|
||||
*/
|
||||
@Nullable URI postForLocation(String url, @Nullable Object request, Map<String, ?> uriVariables)
|
||||
@Nullable URI postForLocation(String url, @Nullable Object request, Map<String, ? extends @Nullable Object> uriVariables)
|
||||
throws RestClientException;
|
||||
|
||||
/**
|
||||
@@ -217,7 +217,7 @@ public interface RestOperations {
|
||||
* @see HttpEntity
|
||||
*/
|
||||
<T> @Nullable T postForObject(String url, @Nullable Object request, Class<T> responseType,
|
||||
Object... uriVariables) throws RestClientException;
|
||||
@Nullable Object... uriVariables) throws RestClientException;
|
||||
|
||||
/**
|
||||
* Create a new resource by POSTing the given object to the URI template,
|
||||
@@ -238,7 +238,7 @@ public interface RestOperations {
|
||||
* @see HttpEntity
|
||||
*/
|
||||
<T> @Nullable T postForObject(String url, @Nullable Object request, Class<T> responseType,
|
||||
Map<String, ?> uriVariables) throws RestClientException;
|
||||
Map<String, ? extends @Nullable Object> uriVariables) throws RestClientException;
|
||||
|
||||
/**
|
||||
* Create a new resource by POSTing the given object to the URL,
|
||||
@@ -277,7 +277,7 @@ public interface RestOperations {
|
||||
* @see HttpEntity
|
||||
*/
|
||||
<T> ResponseEntity<T> postForEntity(String url, @Nullable Object request, Class<T> responseType,
|
||||
Object... uriVariables) throws RestClientException;
|
||||
@Nullable Object... uriVariables) throws RestClientException;
|
||||
|
||||
/**
|
||||
* Create a new resource by POSTing the given object to the URI template,
|
||||
@@ -298,7 +298,7 @@ public interface RestOperations {
|
||||
* @see HttpEntity
|
||||
*/
|
||||
<T> ResponseEntity<T> postForEntity(String url, @Nullable Object request, Class<T> responseType,
|
||||
Map<String, ?> uriVariables) throws RestClientException;
|
||||
Map<String, ? extends @Nullable Object> uriVariables) throws RestClientException;
|
||||
|
||||
/**
|
||||
* Create a new resource by POSTing the given object to the URL,
|
||||
@@ -332,7 +332,7 @@ public interface RestOperations {
|
||||
* @param uriVariables the variables to expand the template
|
||||
* @see HttpEntity
|
||||
*/
|
||||
void put(String url, @Nullable Object request, Object... uriVariables) throws RestClientException;
|
||||
void put(String url, @Nullable Object request, @Nullable Object... uriVariables) throws RestClientException;
|
||||
|
||||
/**
|
||||
* Creates a new resource by PUTting the given object to URI template.
|
||||
@@ -344,7 +344,7 @@ public interface RestOperations {
|
||||
* @param uriVariables the variables to expand the template
|
||||
* @see HttpEntity
|
||||
*/
|
||||
void put(String url, @Nullable Object request, Map<String, ?> uriVariables) throws RestClientException;
|
||||
void put(String url, @Nullable Object request, Map<String, ? extends @Nullable Object> uriVariables) throws RestClientException;
|
||||
|
||||
/**
|
||||
* Creates a new resource by PUTting the given object to URL.
|
||||
@@ -377,7 +377,7 @@ public interface RestOperations {
|
||||
* @see RestTemplate#setRequestFactory
|
||||
* @see org.springframework.http.client.HttpComponentsClientHttpRequestFactory
|
||||
*/
|
||||
<T> @Nullable T patchForObject(String url, @Nullable Object request, Class<T> responseType, Object... uriVariables)
|
||||
<T> @Nullable T patchForObject(String url, @Nullable Object request, Class<T> responseType, @Nullable Object... uriVariables)
|
||||
throws RestClientException;
|
||||
|
||||
/**
|
||||
@@ -399,7 +399,7 @@ public interface RestOperations {
|
||||
* @see org.springframework.http.client.HttpComponentsClientHttpRequestFactory
|
||||
*/
|
||||
<T> @Nullable T patchForObject(String url, @Nullable Object request, Class<T> responseType,
|
||||
Map<String, ?> uriVariables) throws RestClientException;
|
||||
Map<String, ? extends @Nullable Object> uriVariables) throws RestClientException;
|
||||
|
||||
/**
|
||||
* Update a resource by PATCHing the given object to the URL,
|
||||
@@ -430,7 +430,7 @@ public interface RestOperations {
|
||||
* @param url the URL
|
||||
* @param uriVariables the variables to expand in the template
|
||||
*/
|
||||
void delete(String url, Object... uriVariables) throws RestClientException;
|
||||
void delete(String url, @Nullable Object... uriVariables) throws RestClientException;
|
||||
|
||||
/**
|
||||
* Delete the resources at the specified URI.
|
||||
@@ -438,7 +438,7 @@ public interface RestOperations {
|
||||
* @param url the URL
|
||||
* @param uriVariables the variables to expand the template
|
||||
*/
|
||||
void delete(String url, Map<String, ?> uriVariables) throws RestClientException;
|
||||
void delete(String url, Map<String, ? extends @Nullable Object> uriVariables) throws RestClientException;
|
||||
|
||||
/**
|
||||
* Delete the resources at the specified URL.
|
||||
@@ -456,7 +456,7 @@ public interface RestOperations {
|
||||
* @param uriVariables the variables to expand in the template
|
||||
* @return the value of the {@code Allow} header
|
||||
*/
|
||||
Set<HttpMethod> optionsForAllow(String url, Object... uriVariables) throws RestClientException;
|
||||
Set<HttpMethod> optionsForAllow(String url, @Nullable Object... uriVariables) throws RestClientException;
|
||||
|
||||
/**
|
||||
* Return the value of the {@code Allow} header for the given URI.
|
||||
@@ -465,7 +465,7 @@ public interface RestOperations {
|
||||
* @param uriVariables the variables to expand in the template
|
||||
* @return the value of the {@code Allow} header
|
||||
*/
|
||||
Set<HttpMethod> optionsForAllow(String url, Map<String, ?> uriVariables) throws RestClientException;
|
||||
Set<HttpMethod> optionsForAllow(String url, Map<String, ? extends @Nullable Object> uriVariables) throws RestClientException;
|
||||
|
||||
/**
|
||||
* Return the value of the {@code Allow} header for the given URL.
|
||||
@@ -491,7 +491,7 @@ public interface RestOperations {
|
||||
* @since 3.0.2
|
||||
*/
|
||||
<T> ResponseEntity<T> exchange(String url, HttpMethod method, @Nullable HttpEntity<?> requestEntity,
|
||||
Class<T> responseType, Object... uriVariables) throws RestClientException;
|
||||
Class<T> responseType, @Nullable Object... uriVariables) throws RestClientException;
|
||||
|
||||
/**
|
||||
* Execute the HTTP method to the given URI template, writing the given request entity to the request,
|
||||
@@ -507,7 +507,7 @@ public interface RestOperations {
|
||||
* @since 3.0.2
|
||||
*/
|
||||
<T> ResponseEntity<T> exchange(String url, HttpMethod method, @Nullable HttpEntity<?> requestEntity,
|
||||
Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException;
|
||||
Class<T> responseType, Map<String, ? extends @Nullable Object> uriVariables) throws RestClientException;
|
||||
|
||||
/**
|
||||
* Execute the HTTP method to the given URI template, writing the given request entity to the request,
|
||||
@@ -544,7 +544,7 @@ public interface RestOperations {
|
||||
* @since 3.2
|
||||
*/
|
||||
<T> ResponseEntity<T> exchange(String url,HttpMethod method, @Nullable HttpEntity<?> requestEntity,
|
||||
ParameterizedTypeReference<T> responseType, Object... uriVariables) throws RestClientException;
|
||||
ParameterizedTypeReference<T> responseType, @Nullable Object... uriVariables) throws RestClientException;
|
||||
|
||||
/**
|
||||
* Execute the HTTP method to the given URI template, writing the given
|
||||
@@ -567,7 +567,7 @@ public interface RestOperations {
|
||||
* @since 3.2
|
||||
*/
|
||||
<T> ResponseEntity<T> exchange(String url, HttpMethod method, @Nullable HttpEntity<?> requestEntity,
|
||||
ParameterizedTypeReference<T> responseType, Map<String, ?> uriVariables) throws RestClientException;
|
||||
ParameterizedTypeReference<T> responseType, Map<String, ? extends @Nullable Object> uriVariables) throws RestClientException;
|
||||
|
||||
/**
|
||||
* Execute the HTTP method to the given URI template, writing the given
|
||||
@@ -648,7 +648,7 @@ public interface RestOperations {
|
||||
* @return an arbitrary object, as returned by the {@link ResponseExtractor}
|
||||
*/
|
||||
<T> @Nullable T execute(String uriTemplate, HttpMethod method, @Nullable RequestCallback requestCallback,
|
||||
@Nullable ResponseExtractor<T> responseExtractor, Object... uriVariables)
|
||||
@Nullable ResponseExtractor<T> responseExtractor, @Nullable Object... uriVariables)
|
||||
throws RestClientException;
|
||||
|
||||
/**
|
||||
@@ -663,7 +663,7 @@ public interface RestOperations {
|
||||
* @return an arbitrary object, as returned by the {@link ResponseExtractor}
|
||||
*/
|
||||
<T> @Nullable T execute(String uriTemplate, HttpMethod method, @Nullable RequestCallback requestCallback,
|
||||
@Nullable ResponseExtractor<T> responseExtractor, Map<String, ?> uriVariables)
|
||||
@Nullable ResponseExtractor<T> responseExtractor, Map<String, ? extends @Nullable Object> uriVariables)
|
||||
throws RestClientException;
|
||||
|
||||
/**
|
||||
|
||||
@@ -330,7 +330,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
* @param uriVars the default URI variable values
|
||||
* @since 4.3
|
||||
*/
|
||||
public void setDefaultUriVariables(Map<String, ?> uriVars) {
|
||||
public void setDefaultUriVariables(Map<String, ? extends @Nullable Object> uriVars) {
|
||||
if (this.uriTemplateHandler instanceof DefaultUriBuilderFactory factory) {
|
||||
factory.setDefaultUriVariables(uriVars);
|
||||
}
|
||||
@@ -405,7 +405,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
// GET
|
||||
|
||||
@Override
|
||||
public <T> @Nullable T getForObject(String url, Class<T> responseType, Object... uriVariables) throws RestClientException {
|
||||
public <T> @Nullable T getForObject(String url, Class<T> responseType, @Nullable Object... uriVariables) throws RestClientException {
|
||||
RequestCallback requestCallback = acceptHeaderRequestCallback(responseType);
|
||||
HttpMessageConverterExtractor<T> responseExtractor =
|
||||
new HttpMessageConverterExtractor<>(responseType, getMessageConverters(), logger);
|
||||
@@ -429,7 +429,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> ResponseEntity<T> getForEntity(String url, Class<T> responseType, Object... uriVariables)
|
||||
public <T> ResponseEntity<T> getForEntity(String url, Class<T> responseType, @Nullable Object... uriVariables)
|
||||
throws RestClientException {
|
||||
|
||||
RequestCallback requestCallback = acceptHeaderRequestCallback(responseType);
|
||||
@@ -438,7 +438,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> ResponseEntity<T> getForEntity(String url, Class<T> responseType, Map<String, ?> uriVariables)
|
||||
public <T> ResponseEntity<T> getForEntity(String url, Class<T> responseType, Map<String, ? extends @Nullable Object> uriVariables)
|
||||
throws RestClientException {
|
||||
|
||||
RequestCallback requestCallback = acceptHeaderRequestCallback(responseType);
|
||||
@@ -457,12 +457,12 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
// HEAD
|
||||
|
||||
@Override
|
||||
public HttpHeaders headForHeaders(String url, Object... uriVariables) throws RestClientException {
|
||||
public HttpHeaders headForHeaders(String url, @Nullable Object... uriVariables) throws RestClientException {
|
||||
return nonNull(execute(url, HttpMethod.HEAD, null, headersExtractor(), uriVariables));
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpHeaders headForHeaders(String url, Map<String, ?> uriVariables) throws RestClientException {
|
||||
public HttpHeaders headForHeaders(String url, Map<String, ? extends @Nullable Object> uriVariables) throws RestClientException {
|
||||
return nonNull(execute(url, HttpMethod.HEAD, null, headersExtractor(), uriVariables));
|
||||
}
|
||||
|
||||
@@ -475,7 +475,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
// POST
|
||||
|
||||
@Override
|
||||
public @Nullable URI postForLocation(String url, @Nullable Object request, Object... uriVariables)
|
||||
public @Nullable URI postForLocation(String url, @Nullable Object request, @Nullable Object... uriVariables)
|
||||
throws RestClientException {
|
||||
|
||||
RequestCallback requestCallback = httpEntityCallback(request);
|
||||
@@ -484,7 +484,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable URI postForLocation(String url, @Nullable Object request, Map<String, ?> uriVariables)
|
||||
public @Nullable URI postForLocation(String url, @Nullable Object request, Map<String, ? extends @Nullable Object> uriVariables)
|
||||
throws RestClientException {
|
||||
|
||||
RequestCallback requestCallback = httpEntityCallback(request);
|
||||
@@ -501,7 +501,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
|
||||
@Override
|
||||
public <T> @Nullable T postForObject(String url, @Nullable Object request, Class<T> responseType,
|
||||
Object... uriVariables) throws RestClientException {
|
||||
@Nullable Object... uriVariables) throws RestClientException {
|
||||
|
||||
RequestCallback requestCallback = httpEntityCallback(request, responseType);
|
||||
HttpMessageConverterExtractor<T> responseExtractor =
|
||||
@@ -511,7 +511,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
|
||||
@Override
|
||||
public <T> @Nullable T postForObject(String url, @Nullable Object request, Class<T> responseType,
|
||||
Map<String, ?> uriVariables) throws RestClientException {
|
||||
Map<String, ? extends @Nullable Object> uriVariables) throws RestClientException {
|
||||
|
||||
RequestCallback requestCallback = httpEntityCallback(request, responseType);
|
||||
HttpMessageConverterExtractor<T> responseExtractor =
|
||||
@@ -531,7 +531,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
|
||||
@Override
|
||||
public <T> ResponseEntity<T> postForEntity(String url, @Nullable Object request,
|
||||
Class<T> responseType, Object... uriVariables) throws RestClientException {
|
||||
Class<T> responseType, @Nullable Object... uriVariables) throws RestClientException {
|
||||
|
||||
RequestCallback requestCallback = httpEntityCallback(request, responseType);
|
||||
ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(responseType);
|
||||
@@ -540,7 +540,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
|
||||
@Override
|
||||
public <T> ResponseEntity<T> postForEntity(String url, @Nullable Object request,
|
||||
Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException {
|
||||
Class<T> responseType, Map<String, ? extends @Nullable Object> uriVariables) throws RestClientException {
|
||||
|
||||
RequestCallback requestCallback = httpEntityCallback(request, responseType);
|
||||
ResponseExtractor<ResponseEntity<T>> responseExtractor = responseEntityExtractor(responseType);
|
||||
@@ -560,7 +560,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
// PUT
|
||||
|
||||
@Override
|
||||
public void put(String url, @Nullable Object request, Object... uriVariables)
|
||||
public void put(String url, @Nullable Object request, @Nullable Object... uriVariables)
|
||||
throws RestClientException {
|
||||
|
||||
RequestCallback requestCallback = httpEntityCallback(request);
|
||||
@@ -568,7 +568,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(String url, @Nullable Object request, Map<String, ?> uriVariables)
|
||||
public void put(String url, @Nullable Object request, Map<String, ? extends @Nullable Object> uriVariables)
|
||||
throws RestClientException {
|
||||
|
||||
RequestCallback requestCallback = httpEntityCallback(request);
|
||||
@@ -586,7 +586,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
|
||||
@Override
|
||||
public <T> @Nullable T patchForObject(String url, @Nullable Object request, Class<T> responseType,
|
||||
Object... uriVariables) throws RestClientException {
|
||||
@Nullable Object... uriVariables) throws RestClientException {
|
||||
|
||||
RequestCallback requestCallback = httpEntityCallback(request, responseType);
|
||||
HttpMessageConverterExtractor<T> responseExtractor =
|
||||
@@ -596,7 +596,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
|
||||
@Override
|
||||
public <T> @Nullable T patchForObject(String url, @Nullable Object request, Class<T> responseType,
|
||||
Map<String, ?> uriVariables) throws RestClientException {
|
||||
Map<String, ? extends @Nullable Object> uriVariables) throws RestClientException {
|
||||
|
||||
RequestCallback requestCallback = httpEntityCallback(request, responseType);
|
||||
HttpMessageConverterExtractor<T> responseExtractor =
|
||||
@@ -618,12 +618,12 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
// DELETE
|
||||
|
||||
@Override
|
||||
public void delete(String url, Object... uriVariables) throws RestClientException {
|
||||
public void delete(String url, @Nullable Object... uriVariables) throws RestClientException {
|
||||
execute(url, HttpMethod.DELETE, null, null, uriVariables);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String url, Map<String, ?> uriVariables) throws RestClientException {
|
||||
public void delete(String url, Map<String, ? extends @Nullable Object> uriVariables) throws RestClientException {
|
||||
execute(url, HttpMethod.DELETE, null, null, uriVariables);
|
||||
}
|
||||
|
||||
@@ -636,14 +636,14 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
// OPTIONS
|
||||
|
||||
@Override
|
||||
public Set<HttpMethod> optionsForAllow(String url, Object... uriVariables) throws RestClientException {
|
||||
public Set<HttpMethod> optionsForAllow(String url, @Nullable Object... uriVariables) throws RestClientException {
|
||||
ResponseExtractor<HttpHeaders> headersExtractor = headersExtractor();
|
||||
HttpHeaders headers = execute(url, HttpMethod.OPTIONS, null, headersExtractor, uriVariables);
|
||||
return (headers != null ? headers.getAllow() : Collections.emptySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<HttpMethod> optionsForAllow(String url, Map<String, ?> uriVariables) throws RestClientException {
|
||||
public Set<HttpMethod> optionsForAllow(String url, Map<String, ? extends @Nullable Object> uriVariables) throws RestClientException {
|
||||
ResponseExtractor<HttpHeaders> headersExtractor = headersExtractor();
|
||||
HttpHeaders headers = execute(url, HttpMethod.OPTIONS, null, headersExtractor, uriVariables);
|
||||
return (headers != null ? headers.getAllow() : Collections.emptySet());
|
||||
@@ -661,7 +661,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
|
||||
@Override
|
||||
public <T> ResponseEntity<T> exchange(String url, HttpMethod method,
|
||||
@Nullable HttpEntity<?> requestEntity, Class<T> responseType, Object... uriVariables)
|
||||
@Nullable HttpEntity<?> requestEntity, Class<T> responseType, @Nullable Object... uriVariables)
|
||||
throws RestClientException {
|
||||
|
||||
RequestCallback requestCallback = httpEntityCallback(requestEntity, responseType);
|
||||
@@ -671,7 +671,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
|
||||
@Override
|
||||
public <T> ResponseEntity<T> exchange(String url, HttpMethod method,
|
||||
@Nullable HttpEntity<?> requestEntity, Class<T> responseType, Map<String, ?> uriVariables)
|
||||
@Nullable HttpEntity<?> requestEntity, Class<T> responseType, Map<String, ? extends @Nullable Object> uriVariables)
|
||||
throws RestClientException {
|
||||
|
||||
RequestCallback requestCallback = httpEntityCallback(requestEntity, responseType);
|
||||
@@ -690,7 +690,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
|
||||
@Override
|
||||
public <T> ResponseEntity<T> exchange(String url, HttpMethod method, @Nullable HttpEntity<?> requestEntity,
|
||||
ParameterizedTypeReference<T> responseType, Object... uriVariables) throws RestClientException {
|
||||
ParameterizedTypeReference<T> responseType, @Nullable Object... uriVariables) throws RestClientException {
|
||||
|
||||
Type type = responseType.getType();
|
||||
RequestCallback requestCallback = httpEntityCallback(requestEntity, type);
|
||||
@@ -700,7 +700,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
|
||||
@Override
|
||||
public <T> ResponseEntity<T> exchange(String url, HttpMethod method, @Nullable HttpEntity<?> requestEntity,
|
||||
ParameterizedTypeReference<T> responseType, Map<String, ?> uriVariables) throws RestClientException {
|
||||
ParameterizedTypeReference<T> responseType, Map<String, ? extends @Nullable Object> uriVariables) throws RestClientException {
|
||||
|
||||
Type type = responseType.getType();
|
||||
RequestCallback requestCallback = httpEntityCallback(requestEntity, type);
|
||||
@@ -779,7 +779,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
*/
|
||||
@Override
|
||||
public <T> @Nullable T execute(String uriTemplate, HttpMethod method, @Nullable RequestCallback requestCallback,
|
||||
@Nullable ResponseExtractor<T> responseExtractor, Object... uriVariables) throws RestClientException {
|
||||
@Nullable ResponseExtractor<T> responseExtractor, @Nullable Object... uriVariables) throws RestClientException {
|
||||
|
||||
URI url = getUriTemplateHandler().expand(uriTemplate, uriVariables);
|
||||
return doExecute(url, uriTemplate, method, requestCallback, responseExtractor);
|
||||
@@ -798,7 +798,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat
|
||||
*/
|
||||
@Override
|
||||
public <T> @Nullable T execute(String uriTemplate, HttpMethod method, @Nullable RequestCallback requestCallback,
|
||||
@Nullable ResponseExtractor<T> responseExtractor, Map<String, ?> uriVariables)
|
||||
@Nullable ResponseExtractor<T> responseExtractor, Map<String, ? extends @Nullable Object> uriVariables)
|
||||
throws RestClientException {
|
||||
|
||||
URI url = getUriTemplateHandler().expand(uriTemplate, uriVariables);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -49,7 +49,7 @@ public class DefaultUriBuilderFactory implements UriBuilderFactory {
|
||||
|
||||
private EncodingMode encodingMode = EncodingMode.TEMPLATE_AND_VALUES;
|
||||
|
||||
private @Nullable Map<String, Object> defaultUriVariables;
|
||||
private @Nullable Map<String, @Nullable Object> defaultUriVariables;
|
||||
|
||||
private boolean parsePath = true;
|
||||
|
||||
@@ -140,7 +140,7 @@ public class DefaultUriBuilderFactory implements UriBuilderFactory {
|
||||
* with a Map of variables.
|
||||
* @param defaultUriVariables default URI variable values
|
||||
*/
|
||||
public void setDefaultUriVariables(@Nullable Map<String, ?> defaultUriVariables) {
|
||||
public void setDefaultUriVariables(@Nullable Map<String, ? extends @Nullable Object> defaultUriVariables) {
|
||||
if (defaultUriVariables != null) {
|
||||
if (this.defaultUriVariables == null) {
|
||||
this.defaultUriVariables = new HashMap<>(defaultUriVariables);
|
||||
@@ -192,12 +192,12 @@ public class DefaultUriBuilderFactory implements UriBuilderFactory {
|
||||
// UriTemplateHandler
|
||||
|
||||
@Override
|
||||
public URI expand(String uriTemplate, Map<String, ?> uriVars) {
|
||||
public URI expand(String uriTemplate, Map<String, ? extends @Nullable Object> uriVars) {
|
||||
return uriString(uriTemplate).build(uriVars);
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI expand(String uriTemplate, Object... uriVars) {
|
||||
public URI expand(String uriTemplate, @Nullable Object... uriVars) {
|
||||
return uriString(uriTemplate).build(uriVars);
|
||||
}
|
||||
|
||||
@@ -446,7 +446,7 @@ public class DefaultUriBuilderFactory implements UriBuilderFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI build(Object... uriVars) {
|
||||
public URI build(@Nullable Object... uriVars) {
|
||||
if (ObjectUtils.isEmpty(uriVars) && !CollectionUtils.isEmpty(defaultUriVariables)) {
|
||||
return build(Collections.emptyMap());
|
||||
}
|
||||
|
||||
@@ -261,7 +261,7 @@ public interface UriBuilder {
|
||||
* @param uriVariables the map of URI variables
|
||||
* @return the URI
|
||||
*/
|
||||
URI build(Object... uriVariables);
|
||||
URI build(@Nullable Object... uriVariables);
|
||||
|
||||
/**
|
||||
* Build a {@link URI} instance and replaces URI template variables
|
||||
@@ -269,7 +269,7 @@ public interface UriBuilder {
|
||||
* @param uriVariables the map of URI variables
|
||||
* @return the URI
|
||||
*/
|
||||
URI build(Map<String, ?> uriVariables);
|
||||
URI build(Map<String, ? extends @Nullable Object> uriVariables);
|
||||
|
||||
/**
|
||||
* Return a String representation of the URI by concatenating all URI
|
||||
|
||||
@@ -148,7 +148,7 @@ public abstract class UriComponents implements Serializable {
|
||||
* @param uriVariables the map of URI variables
|
||||
* @return the expanded URI components
|
||||
*/
|
||||
public final UriComponents expand(Map<String, ?> uriVariables) {
|
||||
public final UriComponents expand(Map<String, ? extends @Nullable Object> uriVariables) {
|
||||
Assert.notNull(uriVariables, "'uriVariables' must not be null");
|
||||
return expandInternal(new MapTemplateVariables(uriVariables));
|
||||
}
|
||||
@@ -159,7 +159,7 @@ public abstract class UriComponents implements Serializable {
|
||||
* @param uriVariableValues the URI variable values
|
||||
* @return the expanded URI components
|
||||
*/
|
||||
public final UriComponents expand(Object... uriVariableValues) {
|
||||
public final UriComponents expand(@Nullable Object... uriVariableValues) {
|
||||
Assert.notNull(uriVariableValues, "'uriVariableValues' must not be null");
|
||||
return expandInternal(new VarArgsTemplateVariables(uriVariableValues));
|
||||
}
|
||||
@@ -324,9 +324,9 @@ public abstract class UriComponents implements Serializable {
|
||||
*/
|
||||
private static class MapTemplateVariables implements UriTemplateVariables {
|
||||
|
||||
private final Map<String, ?> uriVariables;
|
||||
private final Map<String, ? extends @Nullable Object> uriVariables;
|
||||
|
||||
public MapTemplateVariables(Map<String, ?> uriVariables) {
|
||||
public MapTemplateVariables(Map<String, ? extends @Nullable Object> uriVariables) {
|
||||
this.uriVariables = uriVariables;
|
||||
}
|
||||
|
||||
@@ -347,7 +347,7 @@ public abstract class UriComponents implements Serializable {
|
||||
|
||||
private final Iterator<Object> valueIterator;
|
||||
|
||||
public VarArgsTemplateVariables(Object... uriVariableValues) {
|
||||
public VarArgsTemplateVariables(@Nullable Object... uriVariableValues) {
|
||||
this.valueIterator = Arrays.asList(uriVariableValues).iterator();
|
||||
}
|
||||
|
||||
|
||||
@@ -337,17 +337,17 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
|
||||
* @param uriVariableValues the URI variable values
|
||||
* @return the URI components with expanded values
|
||||
*/
|
||||
public UriComponents buildAndExpand(Object... uriVariableValues) {
|
||||
public UriComponents buildAndExpand(@Nullable Object... uriVariableValues) {
|
||||
return build().expand(uriVariableValues);
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI build(Object... uriVariables) {
|
||||
public URI build(@Nullable Object... uriVariables) {
|
||||
return buildInternal(EncodingHint.ENCODE_TEMPLATE).expand(uriVariables).toUri();
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI build(Map<String, ?> uriVariables) {
|
||||
public URI build(Map<String, ? extends @Nullable Object> uriVariables) {
|
||||
return buildInternal(EncodingHint.ENCODE_TEMPLATE).expand(uriVariables).toUri();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ package org.springframework.web.util;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Defines methods for expanding a URI template with variables.
|
||||
*
|
||||
@@ -34,7 +36,7 @@ public interface UriTemplateHandler {
|
||||
* @param uriVariables variable values
|
||||
* @return the created URI instance
|
||||
*/
|
||||
URI expand(String uriTemplate, Map<String, ?> uriVariables);
|
||||
URI expand(String uriTemplate, Map<String, ? extends @Nullable Object> uriVariables);
|
||||
|
||||
/**
|
||||
* Expand the given URI template with an array of URI variables.
|
||||
@@ -42,6 +44,6 @@ public interface UriTemplateHandler {
|
||||
* @param uriVariables variable values
|
||||
* @return the created URI instance
|
||||
*/
|
||||
URI expand(String uriTemplate, Object... uriVariables);
|
||||
URI expand(String uriTemplate, @Nullable Object... uriVariables);
|
||||
|
||||
}
|
||||
|
||||
@@ -325,7 +325,7 @@ public abstract class UriUtils {
|
||||
* @return the encoded String
|
||||
* @since 5.0
|
||||
*/
|
||||
public static Map<String, String> encodeUriVariables(Map<String, ?> uriVariables) {
|
||||
public static Map<String, String> encodeUriVariables(Map<String, ? extends @Nullable Object> uriVariables) {
|
||||
Map<String, String> result = CollectionUtils.newLinkedHashMap(uriVariables.size());
|
||||
uriVariables.forEach((key, value) -> {
|
||||
String stringValue = (value != null ? value.toString() : "");
|
||||
@@ -341,7 +341,7 @@ public abstract class UriUtils {
|
||||
* @return the encoded String
|
||||
* @since 5.0
|
||||
*/
|
||||
public static Object[] encodeUriVariables(Object... uriVariables) {
|
||||
public static Object[] encodeUriVariables(@Nullable Object... uriVariables) {
|
||||
return Arrays.stream(uriVariables)
|
||||
.map(value -> {
|
||||
String stringValue = (value != null ? value.toString() : "");
|
||||
|
||||
Reference in New Issue
Block a user