Why:PATCH is used to apply a partial change to an existing resource on the server.
2. Which annotation maps a controller method to HTTP PATCH requests in Spring MVC?
Why:@PatchMapping is the shortcut annotation for handling HTTP PATCH requests.
3. Which annotation should be placed before the parameter so that the JSON body of a PATCH request is converted to a Java object?
@PatchMapping("/items/{id}")
@ResponseBody
public String update(/* annotation here */ Item item) {
return "Updated";
}
Why:@RequestBody tells Spring MVC to read the request body and convert it to the parameter type.
4. Which request header tells Spring MVC that the request body contains JSON data?
Why: The Content-Type header with the value application/json tells the server that the body is JSON.
5. Which Spring MVC component converts a JSON request body into a Java object?
Why: An HttpMessageConverter reads the request body and converts it to a Java object. It also converts Java objects to a response body.
6. Which library is commonly added to the classpath so Spring MVC can convert JSON to Java objects?
Why: Spring MVC uses Jackson to read and write JSON when it is available on the classpath.
7. What usually happens if a JSON body is sent to a method using @RequestBody but no JSON library is on the classpath?
Why: Without a JSON library, Spring MVC has no converter for JSON, so the request fails with an unsupported media type error.
8. Which annotation on a configuration class enables Spring MVC with its default message converters?
Why:@EnableWebMvc turns on Spring MVC configuration and registers default message converters. A JSON converter is added when the JSON library is present.
9. A controller method returns a String that should be sent directly as the response body, not used as a view name. Which annotation is needed?
Why:@ResponseBody tells Spring MVC to write the return value to the response body instead of resolving it as a view name.
10. How does Jackson usually match the fields of a JSON body to a Java object?
Why: Jackson maps each JSON field to the Java property that has the same name.
11. A normal HTML form can only send GET and POST requests. How can a web page send a PATCH request with a JSON body?
Why: Browsers do not support PATCH in HTML forms. JavaScript (AJAX) can send a PATCH request with a JSON body.
12. A PATCH mapping uses the URL /articles/{id}. Which annotation reads the id value from the URL?
Why:@PathVariable binds a value from the URL template, such as {id}, to a method parameter.