开发者

jersey webservice not returning jsonp

开发者 https://www.devze.com 2023-01-01 13:23 出处:网络
I am trying to create a webservice that will return jsonp. At the moment it is only returning json Here is my code:

I am trying to create a webservice that will return jsonp. At the moment it is only returning 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: " + jsoncallba开发者_C百科ck); 
        return new JSONWithPadding( new GenericEntity<ToolKitBean>(tkBean) {}, jsoncallback);

    }   

}

i also have a JAXBContext resolver defined. When i look at the response from this webservice, I see the json and not jsonp - {"negativeCount":"10","positiveCount":"11"}

Any ideas what I need to do in order to have jsonP returned from this webservice?

Thanks DAmien


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

This has fixed my issue

Thanks Damien

0

精彩评论

暂无评论...
验证码 换一张
取 消