Add consumes attribute to @GetMapping
Issue: SPR-14988
This commit is contained in:
committed by
Rossen Stoyanchev
parent
9d37472f23
commit
e707c40e0b
@@ -31,9 +31,6 @@ import org.springframework.core.annotation.AliasFor;
|
||||
* <p>Specifically, {@code @GetMapping} is a <em>composed annotation</em> that
|
||||
* acts as a shortcut for {@code @RequestMapping(method = RequestMethod.GET)}.
|
||||
*
|
||||
* <h5>Difference between {@code @GetMapping} & {@code @RequestMapping}</h5>
|
||||
* <p>{@code @GetMapping} does not support the {@link RequestMapping#consumes consumes}
|
||||
* attribute of {@code @RequestMapping}.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 4.3
|
||||
@@ -79,6 +76,13 @@ public @interface GetMapping {
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] headers() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#consumes}.
|
||||
* @since 4.3.5
|
||||
*/
|
||||
@AliasFor(annotation = RequestMapping.class)
|
||||
String[] consumes() default {};
|
||||
|
||||
/**
|
||||
* Alias for {@link RequestMapping#produces}.
|
||||
*/
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
@@ -145,6 +146,14 @@ public class RequestMappingHandlerMappingTests {
|
||||
info.getProducesCondition().getProducibleMediaTypes().iterator().next().toString());
|
||||
}
|
||||
|
||||
@Test // SPR-14988
|
||||
public void getMappingOverridesConsumesFromTypeLevelAnnotation() throws Exception {
|
||||
RequestMappingInfo requestMappingInfo = assertComposedAnnotationMapping(RequestMethod.GET);
|
||||
|
||||
assertArrayEquals(new MediaType[]{MediaType.ALL}, new ArrayList<>(
|
||||
requestMappingInfo.getConsumesCondition().getConsumableMediaTypes()).toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMapping() throws Exception {
|
||||
assertComposedAnnotationMapping(RequestMethod.GET);
|
||||
@@ -199,6 +208,7 @@ public class RequestMappingHandlerMappingTests {
|
||||
|
||||
|
||||
@Controller
|
||||
@RequestMapping(consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
static class ComposedAnnotationController {
|
||||
|
||||
@RequestMapping
|
||||
@@ -209,7 +219,7 @@ public class RequestMappingHandlerMappingTests {
|
||||
public void postJson() {
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@GetMapping(value = "/get", consumes = MediaType.ALL_VALUE)
|
||||
public void get() {
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user