Content Negotiation — Concept Check
Questions on Content Negotiation. Spring MVC selects the response format (JSON, XML, etc.) based on Accept headers or URL suffixes, driven by registered HttpMessageConverters.
Questions in this quiz
8 questions on Content Negotiation — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A client sends a request with the Accept header set to 'application/xml'. What will Spring MVC do if no HttpMessageConverter supports XML?
- AReturn 415 Unsupported Media Type
- BReturn 500 Internal Server Error
- CReturn 406 Not Acceptable
- DReturn 200 OK with default JSON
2.A developer wants to add CSV support to their Spring MVC application. What should they do?
- AUse Jackson's MappingJackson2HttpMessageConverter
- BAdd JAXB annotations to entities
- CImplement a custom HttpMessageConverter
- DAdd 'text/csv' to the Accept header
3.A Spring Boot application returns JSON instead of XML despite the client requesting XML. What could be the reason?
- AThe URL extension is incorrect
- BJAXB dependencies are missing
- CThe server is ignoring Accept headers
- DJackson is misconfigured
4.Which media type will be used if a client sends an Accept header with both 'application/json' and 'application/xml'?
- AThe first matching converter in the registered order
- BThe last matching converter in the registered order
- CAlways JSON
- DAlways XML
5.A client sends XML data to an endpoint that only consumes JSON. What will happen?
- AReturn 200 OK with empty response
- BReturn 406 Not Acceptable
- CConvert XML to JSON automatically
- DReturn 415 Unsupported Media Type
6.An endpoint is configured with 'produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE}'. What determines the response format?
- AThe URL extension
- BThe server's default setting
- CThe order of media types in the 'produces' array
- DThe client's Accept header
7.A developer adds a custom CSV converter but JSON is still being returned. What might be the issue?
- AThe CSV converter is not registered correctly
- BCSV is not supported by Spring MVC
- CJackson is overriding the CSV converter
- DThe client is not sending Accept: text/csv
8.What happens if a client requests 'application/json' but the server only supports 'application/xml'?
- AReturn 200 OK with XML response
- BReturn 406 Not Acceptable
- CReturn 415 Unsupported Media Type
- DConvert XML to JSON automatically