diff --git a/spring-web/src/main/kotlin/org/springframework/web/client/RestOperationsExtensions.kt b/spring-web/src/main/kotlin/org/springframework/web/client/RestOperationsExtensions.kt index 274bcb9ea19..a7ec9277fea 100644 --- a/spring-web/src/main/kotlin/org/springframework/web/client/RestOperationsExtensions.kt +++ b/spring-web/src/main/kotlin/org/springframework/web/client/RestOperationsExtensions.kt @@ -115,7 +115,8 @@ inline fun RestOperations.getForEntity(url: String, uriVariable * @since 5.0.2 */ @Throws(RestClientException::class) -inline fun RestOperations.patchForObject(url: String, request: Any, vararg uriVariables: Any): T? = +inline fun RestOperations.patchForObject(url: String, request: Any? = null, + vararg uriVariables: Any): T? = patchForObject(url, request, T::class.java, *uriVariables) /** @@ -128,7 +129,8 @@ inline fun RestOperations.patchForObject(url: String, request: * @since 5.0.2 */ @Throws(RestClientException::class) -inline fun RestOperations.patchForObject(url: String, request: Any, uriVariables: Map): T? = +inline fun RestOperations.patchForObject(url: String, request: Any? = null, + uriVariables: Map): T? = patchForObject(url, request, T::class.java, uriVariables) /** @@ -141,7 +143,7 @@ inline fun RestOperations.patchForObject(url: String, request: * @since 5.0.2 */ @Throws(RestClientException::class) -inline fun RestOperations.patchForObject(url: URI, request: Any): T? = +inline fun RestOperations.patchForObject(url: URI, request: Any? = null): T? = patchForObject(url, request, T::class.java) /** @@ -155,7 +157,8 @@ inline fun RestOperations.patchForObject(url: URI, request: Any * @since 5.0 */ @Throws(RestClientException::class) -inline fun RestOperations.postForObject(url: String, request: Any, vararg uriVariables: Any): T? = +inline fun RestOperations.postForObject(url: String, request: Any? = null, + vararg uriVariables: Any): T? = postForObject(url, request, T::class.java, *uriVariables) /** @@ -169,7 +172,8 @@ inline fun RestOperations.postForObject(url: String, request: A * @since 5.0 */ @Throws(RestClientException::class) -inline fun RestOperations.postForObject(url: String, request: Any, uriVariables: Map): T? = +inline fun RestOperations.postForObject(url: String, request: Any? = null, + uriVariables: Map): T? = postForObject(url, request, T::class.java, uriVariables) /** @@ -183,7 +187,7 @@ inline fun RestOperations.postForObject(url: String, request: A * @since 5.0 */ @Throws(RestClientException::class) -inline fun RestOperations.postForObject(url: URI, request: Any): T? = +inline fun RestOperations.postForObject(url: URI, request: Any? = null): T? = postForObject(url, request, T::class.java) /** @@ -197,7 +201,7 @@ inline fun RestOperations.postForObject(url: URI, request: Any) * @since 5.0 */ @Throws(RestClientException::class) -inline fun RestOperations.postForEntity(url: String, request: Any, +inline fun RestOperations.postForEntity(url: String, request: Any? = null, vararg uriVariables: Any): ResponseEntity = postForEntity(url, request, T::class.java, *uriVariables) @@ -212,7 +216,7 @@ inline fun RestOperations.postForEntity(url: String, request: A * @since 5.0 */ @Throws(RestClientException::class) -inline fun RestOperations.postForEntity(url: String, request: Any, +inline fun RestOperations.postForEntity(url: String, request: Any? = null, uriVariables: Map): ResponseEntity = postForEntity(url, request, T::class.java, uriVariables) @@ -227,7 +231,7 @@ inline fun RestOperations.postForEntity(url: String, request: A * @since 5.0 */ @Throws(RestClientException::class) -inline fun RestOperations.postForEntity(url: URI, request: Any): ResponseEntity = +inline fun RestOperations.postForEntity(url: URI, request: Any? = null): ResponseEntity = postForEntity(url, request, T::class.java) /** @@ -241,7 +245,7 @@ inline fun RestOperations.postForEntity(url: URI, request: Any) */ @Throws(RestClientException::class) inline fun RestOperations.exchange(url: String, method: HttpMethod, - requestEntity: HttpEntity<*>, vararg uriVariables: Any): ResponseEntity = + requestEntity: HttpEntity<*>? = null, vararg uriVariables: Any): ResponseEntity = exchange(url, method, requestEntity, object : ParameterizedTypeReference() {}, *uriVariables) /** @@ -255,7 +259,7 @@ inline fun RestOperations.exchange(url: String, method: HttpMet */ @Throws(RestClientException::class) inline fun RestOperations.exchange(url: String, method: HttpMethod, - requestEntity: HttpEntity<*>, uriVariables: Map): ResponseEntity = + requestEntity: HttpEntity<*>? = null, uriVariables: Map): ResponseEntity = exchange(url, method, requestEntity, object : ParameterizedTypeReference() {}, uriVariables) /** @@ -269,7 +273,7 @@ inline fun RestOperations.exchange(url: String, method: HttpMet */ @Throws(RestClientException::class) inline fun RestOperations.exchange(url: URI, method: HttpMethod, - requestEntity: HttpEntity<*>): ResponseEntity = + requestEntity: HttpEntity<*>? = null): ResponseEntity = exchange(url, method, requestEntity, object : ParameterizedTypeReference() {}) /** diff --git a/spring-web/src/test/kotlin/org/springframework/web/client/RestOperationsExtensionsTests.kt b/spring-web/src/test/kotlin/org/springframework/web/client/RestOperationsExtensionsTests.kt index 6b0e42e399e..5841c054886 100644 --- a/spring-web/src/test/kotlin/org/springframework/web/client/RestOperationsExtensionsTests.kt +++ b/spring-web/src/test/kotlin/org/springframework/web/client/RestOperationsExtensionsTests.kt @@ -112,13 +112,20 @@ class RestOperationsExtensionsTests { } @Test - fun `patchForObject with reified type parameters`() { + fun `patchForObject with reified type parameters and String`() { val url = "https://spring.io" val body: Any = "body" template.patchForObject(url, body) verify(template, times(1)).patchForObject(url, body, Foo::class.java) } + @Test + fun `patchForObject with reified type parameters`() { + val url = "https://spring.io" + template.patchForObject(url) + verify(template, times(1)).patchForObject(url, null, Foo::class.java) + } + @Test fun `postForObject with reified type parameters, String and varargs`() { val url = "https://spring.io" @@ -139,13 +146,20 @@ class RestOperationsExtensionsTests { } @Test - fun `postForObject with reified type parameters`() { + fun `postForObject with reified type parameters and String`() { val url = "https://spring.io" val body: Any = "body" template.postForObject(url, body) verify(template, times(1)).postForObject(url, body, Foo::class.java) } + @Test + fun `postForObject with reified type parameters`() { + val url = "https://spring.io" + template.postForObject(url) + verify(template, times(1)).postForObject(url, null, Foo::class.java) + } + @Test fun `postForEntity with reified type parameters, String and varargs`() { val url = "https://spring.io" @@ -166,13 +180,20 @@ class RestOperationsExtensionsTests { } @Test - fun `postForEntity with reified type parameters`() { + fun `postForEntity with reified type parameters and String`() { val url = "https://spring.io" val body: Any = "body" template.postForEntity(url, body) verify(template, times(1)).postForEntity(url, body, Foo::class.java) } + @Test + fun `postForEntity with reified type parameters`() { + val url = "https://spring.io" + template.postForEntity(url) + verify(template, times(1)).postForEntity(url, null, Foo::class.java) + } + @Test fun `exchange with reified type parameters, String, HttpMethod, HttpEntity and varargs`() { val url = "https://spring.io" @@ -197,7 +218,7 @@ class RestOperationsExtensionsTests { } @Test - fun `exchange with reified type parameters, String, HttpMethod, HttpEntity`() { + fun `exchange with reified type parameters, String, HttpMethod and HttpEntity`() { val url = "https://spring.io" val method = HttpMethod.GET val entity = mock>() @@ -207,7 +228,16 @@ class RestOperationsExtensionsTests { } @Test - fun `exchange with reified type parameters, String, HttpEntity`() { + fun `exchange with reified type parameters, String and HttpMethod`() { + val url = "https://spring.io" + val method = HttpMethod.GET + template.exchange>(url, method) + verify(template, times(1)).exchange(url, method, null, + object : ParameterizedTypeReference>() {}) + } + + @Test + fun `exchange with reified type parameters, String and HttpEntity`() { val entity = mock>() template.exchange>(entity) verify(template, times(1)).exchange(entity,