How enable JSONP in RESTEasy?

前端 未结 5 1747
孤城傲影
孤城傲影 2020-12-16 18:15

Title say about my issue. I need wrap DTO in to a javascript method callback. Currently I return on request JSON. But problem with using this in Ajax because I send GET to o

5条回答
  •  余生分开走
    2020-12-16 19:10

    Resteasy claims to support JSONP out of the box in 3.x version:

    If you're using Jackson, Resteasy has JSONP that you can turn on by adding the provider org.jboss.resteasy.plugins.providers.jackson.JacksonJsonpInterceptor (Jackson2JsonpInterceptor if you're using the Jackson2 provider) to your deployments. If the media type of the response is json and a callback query parameter is given, the response will be a javascript snippet with a method call of the method defined by the callback parameter. For example:

    GET /resources/stuff?callback=processStuffResponse will produce this response:

    processStuffResponse() This supports the default behavior of jQuery.

    You can change the name of the callback parameter by setting the callbackQueryParameter property.

    However, it seems that it is broken due to RESTEASY-1168: Jackson2JsonpInterceptor does not render closing bracket

    So foo({"foo":"bar"} is rendered instead of foo({"foo":"bar"})

    And that causes "Uncaught SyntaxError: Unexpected Identifier" error

    I have submitted a pull-request with a fix and hopefully it should get into next release 3.0.12

    I know that this question is pretty old, but it is shown on the first page of Google when you search for resteasy jsonp problems, so I decided to update it

提交回复
热议问题