I understand that custom filters can be used in earlier version of Spring MVC to implement JSONP. Additionally this example describes a method to implement JSONP in Spring MVC 3.1 by extending the MappingJacksonHttpMessageConverter
class and modifying the domain objects.
Is there a simpler (or conventional) method to address JSONP in Spring MVC 3.2 besides using the above methods? I did not see JSONP addressed at all in the Spring 3.2 documentation.
With spring 4.1 you can do this really simply with a @ControllerAdvice
https://spring.io/blog/2014/07/28/spring-framework-4-1-spring-mvc-improvements
Here is the simplest way to handle this scenario
You can simply use the spring-jsonp-support by Bhagya Silva as a dependency on your project.
https://github.com/bhagyas/spring-jsonp-support
More information is available on the README.md file.
I was looking for a simpler, OOB approach for JSONP approach (JSONP/CORS should be built-in IMO...not require any custom code)...never found any...but after reaching out with the Spring team, it turns out that JSONP is now supported OOB in 4.0.5 via
MappingJacksonJsonView
and built-in support for CORS to follow later.simpler way like this