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.
simpler way like this
@RequestMapping(value = "/jsonp", method = RequestMethod.GET)
@ResponseBody
public String jsonp(@RequestParam("c")String callBack) throws Exception{
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> map = new HashMap<String, Object>();
map.put("data", "<p>jsonp data<p>");
return objectMapper.writeValueAsString(new JSONPObject(callBack,map));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With