-
Notifications
You must be signed in to change notification settings - Fork 38.5k
@ResponseBody [SPR-5766] #10436
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
Comments
Arjen Poutsma commented Well, if we are going to use HttpMessageConverters, we do definitely need a explicit annotation to trigger it. This is due to the fact that |
Arjen Poutsma commented Edit the title and replaced HttpMethodConverter with HttpMessageConverter. |
Kenny MacLeod commented How about changing AnnotationMethodHandlerAdapter so that it can be configured with two sets of HttpMessageConverters, one for |
Arjen Poutsma commented Hmm, I am not a big fan of having two sets of HttpMessageConverters. The idea for the message converters is that they work out of the box for common 'machine-to-machine' REST types, like byte[], XML, JSON (forthcoming), etc. If you write your own converter, it should be usable in both request and response scenario's, on both client and server side. For server-side request/response-specific scenarios we already have the WebArgumentResolver and ModelAndViewResolver. Another underlying issue is that return type resolution is already quite complex, and on the verge of being ambiguous, considering all the different return type variants you can have, and also considering the fact that the method name can be significant too. This makes the Spring code for handling these quite hard to understand already, and supporting message converters for return types would make it even harder. Unfortunately, refactoring this code is not an option, because we have to maintain backwards compatibility. Therefore, the main reason for introducing a new, supplemental annotation like I know this is not a very strong argument: it mostly comes down to a matter of taste, and Spring Framework internals. But I do think having a separate |
Kenny MacLeod commented OK, I'm cool with that. Perhaps, for consistency with |
Arjen Poutsma commented Done! |
Kenny MacLeod commented Great stuff. I see that the annotation is defined as only allowed on methods... could it be allowed on the controller class also, indicating that all methods "inherit" it? |
Uh oh!
There was an error while loading. Please reload this page.
Kenny MacLeod opened SPR-5766 and commented
It seems odd and undesirable that the annotation-style of MVC controllers should only make use of HttpMessageConverter on the request, and not the response. Specifically,
@RequestBody
-annotated arguments can be resolved using HttpMessageConverter .read(), but there's no support for rendering the response using HttpMessageConverter .write().This is addressed to some degree in #10100, but I'm focussing here more on writing elegant REST controllers; the controller should be able to take the typed and unmarshalled request body Object, and should be able to return a similarly type Object for marshalling. The ModelAndViewResolver approach suggested in #10100 just doesn't seem right.
Would it be possible for the standard return value resolution logic to consult with any HttpMessageConverters in the context, as happens with
@RequestBody
annotations? There doesn't seem to be a need for a@ResponseBody
annotation.Affects: 3.0 M3
Issue Links:
The text was updated successfully, but these errors were encountered: