Reputation: 40870
I oftentimes want to return an Object as response body which is not supported by spring. So Instead I do:
public HttpEntity<?> doStuff() {
MyClass myObject = ... ;
return SomeHelper.toHttpEntity(myObject);
}
While this works, it is uncool, because it makes my code less testable and adds the same call over and over to various handler methods. Thus I wonder if I could add support for an additional type in spring.
I couldn't find anything on Google, but reading through the source code I found the interface HandlerMethodReturnValueHandler
whose implementors do the conversion. So I'd implement that interface for my custom type, but how do I register it (using XML) in spring?
Upvotes: 0
Views: 1118
Reputation: 26858
I don't think that you need your own HandlerMethodReturnValueHandler
, but just in case:
<mvc:annotation-driven>
<mvc:return-value-handlers>
<bean class="my.own.Handler" />
</mvc:return-value-handlers>
If mvc
is your default namepsace you omit the qualifier, of course.
Upvotes: 1