Jersey webservice does not return jsonp

I am trying to create a web service that will return jsonp. At the moment, it returns json

Here is my code:

@Path("/jsonp") public class JsonpWebservice { @GET @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML}) public JSONWithPadding readAllP(@QueryParam("jsoncallback") @DefaultValue("jsoncallback") String jsoncallback) { ToolKitBean tkBean = new ToolKitBean(); tkBean.setNegativeCount("10"); tkBean.setPositiveCount("11"); System.out.println("jsoncallback: " + jsoncallback); return new JSONWithPadding( new GenericEntity<ToolKitBean>(tkBean) {}, jsoncallback); } } 

i also defines a JAXBContext qualifier. When I look at the response from this web service, I see json, not jsonp - {"negativeCount":"10","positiveCount":"11"}

Any ideas what I need to do to get jsonP back from this web service?

Thanks Damien

+4
source share
1 answer

By changing @Produces ({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) to be @Produces ("application / x-JavaScript")

This fixed my problem.

Thanks Damien

+7
source

Source: https://habr.com/ru/post/1311502/


All Articles