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:
@@ -0,0 +1,57 @@
|
||||
# 01-method-mapping (Spring Boot 4.1.3, JDK 25)
|
||||
server: StudentController on http://localhost:<random port>, seeded with 1=Asha, 2=Ravi
|
||||
|
||||
RestTemplate getForObject(url, Student.class, 1)
|
||||
-> Student[id=1, name=Asha]
|
||||
RestClient get().uri(url, 1).retrieve().body(Student.class)
|
||||
-> Student[id=1, name=Asha] same result: true
|
||||
|
||||
RestTemplate getForEntity(url, Student.class, 2)
|
||||
-> 200 OK application/json Student[id=2, name=Ravi]
|
||||
RestClient get().uri(url, 2).retrieve().toEntity(Student.class)
|
||||
-> 200 OK application/json Student[id=2, name=Ravi] same result: true
|
||||
|
||||
RestTemplate postForObject(url, request, Student.class)
|
||||
-> Student[id=3, name=Meera]
|
||||
RestClient post().uri(url).body(request).retrieve().body(Student.class)
|
||||
-> Student[id=3, name=Meera] same result: true
|
||||
|
||||
RestTemplate postForEntity(url, request, Student.class)
|
||||
-> 201 CREATED /students/3 Student[id=3, name=Kabir]
|
||||
RestClient post().uri(url).body(request).retrieve().toEntity(Student.class)
|
||||
-> 201 CREATED /students/3 Student[id=3, name=Kabir] same result: true
|
||||
|
||||
RestTemplate postForLocation(url, request)
|
||||
-> /students/3
|
||||
RestClient post().uri(url).body(request).retrieve().toBodilessEntity().getHeaders().getLocation()
|
||||
-> /students/3 same result: true
|
||||
|
||||
RestTemplate put(url, request, 1)
|
||||
-> Asha K
|
||||
RestClient put().uri(url, 1).body(request).retrieve().toBodilessEntity()
|
||||
-> Asha K (status 204 NO_CONTENT) same result: true
|
||||
|
||||
RestTemplate delete(url, 1)
|
||||
-> then GET -> 404
|
||||
RestClient delete().uri(url, 1).retrieve().toBodilessEntity()
|
||||
-> then GET -> 404 (delete status 204 NO_CONTENT) same result: true
|
||||
|
||||
RestTemplate headForHeaders(url, 1) content-type
|
||||
-> application/json
|
||||
RestClient head().uri(url, 1).retrieve().toBodilessEntity().getHeaders()
|
||||
-> application/json same result: true
|
||||
|
||||
RestTemplate optionsForAllow(url)
|
||||
-> [GET, HEAD, OPTIONS, POST]
|
||||
RestClient options().uri(url).retrieve().toBodilessEntity().getHeaders().getAllow()
|
||||
-> [GET, HEAD, OPTIONS, POST] same result: true
|
||||
|
||||
RestTemplate exchange(url, GET, new HttpEntity<>(headers), new ParameterizedTypeReference<List<Student>>() {})
|
||||
-> [Student[id=1, name=Asha], Student[id=2, name=Ravi]]
|
||||
RestClient get().uri(url).headers(h -> ...).retrieve().body(new ParameterizedTypeReference<List<Student>>() {})
|
||||
-> [Student[id=1, name=Asha], Student[id=2, name=Ravi]] same result: true
|
||||
|
||||
|
||||
server saw Authorization on both: Bearer tok-123
|
||||
LegacyStudentClient.findById(1) == StudentClient.findById(1): true
|
||||
LegacyStudentClient.findAll(token) == StudentClient.findAll(token): true
|
||||
Reference in New Issue
Block a user