Files
spring-boot-demo/resttemplate-to-restclient/output/20-openrewrite-diff.txt
T

24 lines
1.7 KiB
Plaintext

# 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();