Use the following:
@RequestMapping(consumes = "application/x.company.v1+json",
produces = "application/x.company.v1+json")
Since Spring 4.2, you can create a meta-annotation to avoid repeting yourself:
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@RequestMapping(consumes = "application/x.company.v1+json",
produces = "application/x.company.v1+json")
public @interface CustomJsonV1RequestMapping {
@AliasFor(annotation = RequestMapping.class, attribute = "value")
String[] value() default {};
@AliasFor(annotation = RequestMapping.class, attribute = "method")
RequestMethod[] method() default {};
@AliasFor(annotation = RequestMapping.class, attribute = "params")
String[] params() default {};
@AliasFor(annotation = RequestMapping.class, attribute = "headers")
String[] headers() default {};
@AliasFor(annotation = RequestMapping.class, attribute = "consumes")
String[] consumes() default {};
@AliasFor(annotation = RequestMapping.class, attribute = "produces")
String[] produces() default {};
}
Then you can use it as follows:
@CustomJsonV1RequestMapping(method = GET)
public String getFoo() {
return foo;
}
See this answer for reference.