Bird
0
0

What will happen if a Spring Boot REST controller method returns an object instead of a String?

medium📝 component behavior Q5 of 15
Spring Boot - REST Controllers
What will happen if a Spring Boot REST controller method returns an object instead of a String?
AThe server crashes with an exception
BThe method will cause a compile-time error
CThe object is automatically converted to JSON or XML in the HTTP response
DThe object is ignored and an empty response is sent
Step-by-Step Solution
Solution:
  1. Step 1: Understand Spring Boot's automatic conversion

    Spring Boot uses message converters to automatically convert returned objects into JSON or XML for REST responses.
  2. Step 2: Check other options

    No compile error occurs, the object is not ignored, and the server does not crash just because of returning an object.
  3. Final Answer:

    The object is automatically converted to JSON or XML in the HTTP response -> Option C
  4. Quick Check:

    Returned objects auto-convert to JSON/XML [OK]
Quick Trick: Objects returned auto-convert to JSON/XML [OK]
Common Mistakes:
  • Expecting compile errors for object returns
  • Thinking objects are ignored in response
  • Assuming server crashes on object return

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes