Bird
0
0

Consider this Spring Boot configuration snippet:

medium📝 Debug Q14 of 15
Spring Boot - Request and Response Handling
Consider this Spring Boot configuration snippet:
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
    configurer.favorParameter(true)
              .parameterName("format")
              .defaultContentType(MediaType.APPLICATION_JSON)
              .mediaType("xml", MediaType.APPLICATION_XML)
              .mediaType("json", MediaType.APPLICATION_JSON);
}
What is the likely problem if a client requests /api/data?format=txt?
AThe server will throw an error due to unknown format
BThe server will respond with XML format
CThe server will respond with JSON as default
DThe server will ignore the format parameter and respond with plain text
Step-by-Step Solution
Solution:
  1. Step 1: Analyze configured media types

    Only 'json' and 'xml' are mapped to media types; 'txt' is not recognized.
  2. Step 2: Check default content type behavior

    If the parameter value is unknown, Spring Boot falls back to the default content type, which is JSON here.
  3. Final Answer:

    The server will respond with JSON as default -> Option C
  4. Quick Check:

    Unknown format uses default JSON [OK]
Quick Trick: Unknown format falls back to default content type [OK]
Common Mistakes:
  • Expecting an error for unknown format
  • Assuming XML is default
  • Thinking plain text is sent automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes