Java 21 migration — Application.java source changes#21
Conversation
- Fix H2 2.x DROP TABLE syntax (DROP TABLE IF EXISTS customers) - Update deprecated JdbcTemplate.query() to varargs overload - Replace defunct gturnquist-quoters URL with jsonplaceholder placeholder Co-Authored-By: Phil Bedford <phil.bedford@cognition.ai>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
218ecee
into
devin/1777913688-java21-migration-base
|
|
||
| RestTemplate restTemplate = new RestTemplate(); | ||
| Quote quote = restTemplate.getForObject("http://gturnquist-quoters.cfapps.io/api/random", Quote.class); | ||
| Quote quote = restTemplate.getForObject("https://jsonplaceholder.typicode.com/posts/1", Quote.class); |
There was a problem hiding this comment.
🔴 API response schema mismatch: Quote model fields will all be null when deserializing JSONPlaceholder response
The new URL https://jsonplaceholder.typicode.com/posts/1 returns a JSON object with fields userId, id, title, and body, but the Quote model (hello/model/Quote.java) expects type (String) and value (Value object with id and quote sub-fields). Since none of the JSON fields match, Jackson will silently ignore them (Spring Boot defaults FAIL_ON_UNKNOWN_PROPERTIES to false), and the deserialized Quote will have type=null and value=null. The log.info(quote.toString()) at line 40 will print Quote{type='null', value=null} — the REST call is effectively useless. The same issue applies to the CommandLineRunner bean at line 52-53.
Prompt for agents
The Quote model (hello/model/Quote.java) has fields `type` (String) and `value` (Value), where Value (hello/model/Value.java) has fields `id` (Long) and `quote` (String). The new endpoint https://jsonplaceholder.typicode.com/posts/1 returns JSON with fields userId, id, title, body — none of which map to Quote's fields. Either: (1) update the Quote and Value model classes to match the JSONPlaceholder response schema, (2) find a replacement API that returns data matching the existing Quote model, or (3) create a new model class (e.g. Post) with userId, id, title, body fields and use that instead. The same URL is used in two places: the main() method at line 39 and the CommandLineRunner bean at line 53.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Acknowledged — this schema mismatch is intentional and explicitly in-scope per the parent migration spec, not a bug to fix in this PR.
From the parent session's task spec for this child:
Note: the response shape will not deserialize into
Quote, but logging the result is acceptable for the placeholder; do NOT change theQuotemodel class. The goal here is just that the build compiles and the URL is reachable; runtime behavior is intentionally a stub.
This is also already called out in the PR description's "Review & Testing Checklist":
Confirm that logging a
Quotedeserialized fromjsonplaceholder.typicode.com/posts/1is acceptable as a stub (fields will be null / it may throw at deserialization depending onQuote's shape — the parent task explicitly accepts this).
So: yes, Quote{type='null', value=null} is the expected runtime behavior post-migration. The original gturnquist-quoters.cfapps.io quotes service is dead, and finding/standing up a real replacement (or refactoring to a Post model + new endpoint) is deliberately deferred — the migration's goal here was just compile + reachable URL. Picking a real replacement endpoint or model is a separate follow-up.
Summary
Source-only changes to
src/main/java/hello/Application.javato make it compatible with Spring Boot 3.2.5 / Java 21 / H2 2.x. No build or wrapper files are touched in this PR — those are owned by sibling child sessions on the parent migration branch.Three changes:
DROP TABLE customers IF EXISTS→DROP TABLE IF EXISTS customers. H2 2.x (which ships with Spring Boot 3.x) requires standard SQL syntax forDROP TABLE IF EXISTS.JdbcTemplate.query()overload — switched from the(sql, Object[] args, RowMapper)form to the varargs-last form(sql, RowMapper, Object... args). The boxed-array overload was deprecated in Spring 5 / removed in Spring 6.http://gturnquist-quoters.cfapps.io/api/random(both occurrences) replaced withhttps://jsonplaceholder.typicode.com/posts/1. The original quotes service is dead. Still usingRestTemplate(no swap toRestClient), call signatures unchanged. The placeholder response shape will not deserialize intoQuote, but logging the result is acceptable for a stub — runtime behavior is intentionally degraded; the goal here is just that the build compiles and the URL is reachable.Also verified:
grep -rn 'import javax\.' src/main/java/hello/returns no matches, so nojavax.*→jakarta.*rewrites were needed in the source tree.The base branch for this PR is
devin/1777913688-java21-migration-base(the integration branch where pom/gradle/wrapper changes from sibling sessions land), NOTmaster.Review & Testing Checklist for Human
JdbcTemplate.query()varargs reordering still compiles cleanly once Spring Boot 3.2.5 is on the classpath (this child session does not run the build — that happens on the integration PR).Quotedeserialized fromjsonplaceholder.typicode.com/posts/1is acceptable as a stub (fields will be null / it may throw at deserialization depending onQuote's shape — the parent task explicitly accepts this).src/main/java/hello/rely on the old H2 syntax or deprecatedJdbcTemplate.query()overload.Notes
pom.xml,build.gradle,.mvn/wrapper/maven-wrapper.properties, andgradle/wrapper/gradle-wrapper.propertiesare intentionally untouched.Link to Devin session: https://app.devin.ai/sessions/5e67b22183e34041a60eec70211d1af4
Requested by: @dr-phil
Devin Review