Description
It would be nice to have string constants of common media types to use in annotations, for example, for Spring's @RequestMapping
or Swagger's @ApiResponse
.
Spring has a very limited set of constants in org.springframework.http.MediaType
, where each media is available as MediaType
object and as string constant (with suffix _VALUE
), e.g. MediaType.APPLICATION_JSON
is the MediaType
object and MediaType.APPLICATION_JSON_VALUE
is the string constant application/json
. That's very convenient, but they only provide a handful of media types.
Guava's com.google.common.net.MediaType
provides the most complete set of media types that I know of, but sadly cannot be used as compile-time string constants in annotations. There's a StackOverflow Q/A about this too, in which Guava is recommended, but this limitation is pointed out too.
Would you consider adding such constants? I can imaging writing and maintaining such a list by hand wouldn't be fun, but maybe the code could be generated from the existing MediaType
constants.
A tiny side note: I saw this comment in the code,
// TODO(gak): make these public?
private static final String APPLICATION_TYPE = "application";
private static final String AUDIO_TYPE = "audio";
private static final String IMAGE_TYPE = "image";
private static final String TEXT_TYPE = "text";
private static final String VIDEO_TYPE = "video";
private static final String WILDCARD = "*";
and yea, I think, it would be useful (and I don't see any harm?) if those constants would be public.