Why do I need to specify @Produces
/@Consumes
for REST?
#47187
Replies: 2 comments 3 replies
-
\CC @geoand |
Beta Was this translation helpful? Give feedback.
-
This is not true. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I understand that the widely spread muscle memory is that you annotate everything with
@Produces
, but the http content negotiation should actually just involve the client (specifying theAccept
hearder... or not) and the container (Quarkus with the availableMessageBodyWriter
s), but not my application. The@Produces
and@Consumes
annotations are intended only for rare cases, where the application wants to have different methods invoked, depending on what the client wants.So I'd assume that I can simply add a
MessageBodyWriter
(e.g. the one contained inquarkus-rest[easy]-jaxb
), and my application would be ready to produce that. But instead, Quarkus only recognizes that it can produceapplication/json
, everything else seems to be ignored until I explicitly add that other content types are available.I've seen the limitation that JAXB doesn't currently allow to serialize lists or arrays out of the box. So I even can't simply annotate all my resource classes, I'll have to exclude those methods... but that's another issue.
I have a reproducer here for everybody to play around with.
What do you think?
Beta Was this translation helpful? Give feedback.
All reactions