Spring MVC - JSON to Object Conversion with Jackson 2 MCQ
0/13
0✓
0✗
1. What does Spring MVC use to convert a JSON message body to a Java object?
Why: Spring MVC uses HttpMessageConverter implementations to convert between HTTP message bodies and Java objects. For JSON, a JSON-capable converter does this work.
2. Which annotation on a controller method parameter tells Spring to convert the HTTP request body into a Java object?
Why:@RequestBody tells Spring to read the request body and convert it into the parameter type using a suitable HttpMessageConverter.
3. Which annotation makes Spring write the return value of a controller method directly to the HTTP response body?
Why:@ResponseBody tells Spring to convert the returned object with an HttpMessageConverter and write it to the response body instead of resolving a view.
4. Which message converter does Spring use to convert JSON with the Jackson 2 library?
Why:MappingJackson2HttpMessageConverter converts between JSON and Java objects using Jackson 2. The other converters handle plain strings, raw bytes and XML.
5. When does Spring activate its Jackson 2 JSON message converter automatically?
Why: Spring only registers the Jackson 2 converter if jackson-databind is available on the classpath. No extra configuration is needed after that.
6. What happens if jackson-databind is missing from the classpath?
Why: Without jackson-databind, the Jackson 2 converter is not registered, so Spring cannot convert JSON bodies to Java objects.
7. Which @RequestMapping attribute limits a handler method to requests whose body has a given content type, such as JSON?
Why: The consumes attribute restricts a handler to requests with a matching Content-Type, for example application/json.
8. What does the produces attribute of @RequestMapping specify?
Why:produces declares the media type of the response, for example JSON. It is matched against the Accept header of the request.
9. Which constant represents the JSON media type value in Spring's MediaType class?
Why:MediaType.APPLICATION_JSON_VALUE is the string constant for application/json. You can use it in the consumes and produces attributes.
10. Which HTTP request header tells the server that the request body contains JSON?
Why: The Content-Type header describes the format of the request body. Spring uses it to pick the right HttpMessageConverter.
11. A controller method has @ResponseBody and returns a List of objects. The JSON converter is active. What does the response body look like?
Why: The JSON converter turns a List into a JSON array. Each element of the list becomes one JSON object in that array.
12. What is the status of MappingJackson2HttpMessageConverter as of Spring Framework 7.0?
Why: Since Spring Framework 7.0, MappingJackson2HttpMessageConverter is deprecated. Spring now prefers Jackson 3 support.
13. Which converter is the replacement for MappingJackson2HttpMessageConverter in Spring Framework 7?
Why:JacksonJsonHttpMessageConverter is the replacement. It is built on Jackson 3.
14. In which Spring Framework version is the removal of MappingJackson2HttpMessageConverter planned?
Why: The converter is deprecated in Spring Framework 7.0, and its removal is planned for Spring Framework 7.2.