question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add consumes and produces to HTTP method annotations

See original GitHub issue

Currently, we have separate annotations to define consume and produce media types:

public class MyService {

    @Post("/foo")
    @Consumes("application/json")
    @Produces(MediaTypeNames.JSON)
    public HttpResponse foo(...) {
        ...
    }
}

It’s a bit verbose, so it would be nice if we can specify them in one annotation:

public class MyService {

    @Post(value = "/foo", consumes = "application/json", produces = MediaTypeNames.JSON)
    public HttpResponse foo(...) {
        ...
    }
}

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jrhee17commented, Jul 21, 2022

Oh, I was rather thinking that all defined ways are applied.

    @ExceptionHandler(...)
    @Blocking
    @Post(value = "/foo", consumes = "application/json", produces = MediaTypeNames.JSON)
    @Consumes("application/protobuf")
    public HttpResponse foo(...) { // accepts both json and protobuf
        ...
0reactions
minwooxcommented, Jul 22, 2022

Ok then let’s close this issue. Thank you guys for the opinions. 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using @Consumes and @Produces to Customize Requests ...
The @Produces annotation is used to specify the MIME media types or representations a resource can produce and send back to the client....
Read more >
@Consumes and @Produces - Java EE: RESTful Service with ...
- [Instructor] All resource methods can consume and produce content of almost any type. If you make a post request to a URI...
Read more >
When I put @Consumes and @Produces in post or get?
1 Answer 1 ... @Consumes and @Produces simply tell what media type the HTTP method takes in and returns. so maybe your HTTP...
Read more >
REST Annotations
Applicable on fields or getter/setter of any field REST DTO. This annotation adds HATEOAS links for POST methods on the returned XML or...
Read more >
How to Set JSON Content Type In Spring MVC - Baeldung
How to Set JSON Content Type In Spring MVC ; @RequestMapping(value = "/greetings", method = RequestMethod.POST, consumes="application/json") ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found