Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide string constants for media types to use in annotations #5794

Open
darioseidl opened this issue Nov 28, 2021 · 0 comments
Open

Provide string constants for media types to use in annotations #5794

darioseidl opened this issue Nov 28, 2021 · 0 comments
Labels
P3 package=net type=enhancement Make an existing feature better

Comments

@darioseidl
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 package=net type=enhancement Make an existing feature better
Projects
None yet
Development

No branches or pull requests

2 participants