Add resttemplate-to-restclient module: RestTemplate deprecation on Spring Framework 7.1 / Boot 4.2.0 vs 4.1.3, method mapping, exchange() trap, bridge URI encoding, RestTestClient, OpenRewrite recipe run, with real transcripts

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b7M7FEdeEm3APj16Bu
This commit is contained in:
Claude
2026-11-21 21:26:48 +05:30
parent 5f85ec8d53
commit cbcfb05e35
77 changed files with 2187 additions and 0 deletions
@@ -0,0 +1,23 @@
# 20-openrewrite-diff (io.moderne.recipe:rewrite-spring 0.40.1, rewrite-maven-plugin 6.46.1, Spring Boot 4.2.0)
$ mvn rewrite:run -Drewrite.activeRecipes=io.moderne.java.spring.boot3.MigrateRestTemplateToRestClient
@@ -12 +12 @@ import org.springframework.http.ResponseEntity;
-import org.springframework.web.client.RestTemplate;
+import org.springframework.web.client.RestClient;
@@ -20 +20 @@ public class RemoteClient {
- private final RestTemplate restTemplate = new RestTemplate();
+ private final RestClient restTemplate = RestClient.create();
@@ -29 +29 @@ public class RemoteClient {
- return this.restTemplate.getForObject(this.base + "/students/{id}", Student.class, id);
+ return this.restTemplate.get().uri(this.base + "/students/{id}", id).retrieve().body(Student.class);
@@ -33 +33 @@ public class RemoteClient {
- return this.restTemplate.postForEntity(this.base + "/students", s, Student.class);
+ return this.restTemplate.post().uri(this.base + "/students").body(s).retrieve().toEntity(Student.class);
@@ -37 +37 @@ public class RemoteClient {
- this.restTemplate.delete(this.base + "/students/{id}", id);
+ this.restTemplate.delete().uri(this.base + "/students/{id}", id).retrieve().toBodilessEntity();
@@ -43,3 +43,2 @@ public class RemoteClient {
- return this.restTemplate.exchange(this.base + "/students", HttpMethod.GET, new HttpEntity<>(headers),
- new ParameterizedTypeReference<List<Student>>() {
- }).getBody();
+ return this.restTemplate.method(HttpMethod.GET).uri(this.base + "/students").headers(h -> h.addAll(new HttpEntity<>(headers).getHeaders())).body(new HttpEntity<>(headers).getBody()).retrieve().toEntity(new ParameterizedTypeReference<List<Student>>() {
+ }).getBody();