在Dropwizard中序列化JSONP/JSONPObject
我能够在Dropwizard资源中返回JSON响应,没有任何问题。但是当我试图返回一个JSONPObject时,响应仍然返回一个JSON,而不是请求的回调函数中包装的JSON在Dropwizard中序列化JSONP/JSONPObject,json,jersey,jackson,dropwizard,Json,Jersey,Jackson,Dropwizard,我能够在Dropwizard资源中返回JSON响应,没有任何问题。但是当我试图返回一个JSONPObject时,响应仍然返回一个JSON,而不是请求的回调函数中包装的JSON @Path("/results") @Produces(MediaType.APPLICATION_JSON) public class ExperimentResultResource { ... @Path("results/{experimentId}") @GET @Timed
@Path("/results")
@Produces(MediaType.APPLICATION_JSON)
public class ExperimentResultResource {
...
@Path("results/{experimentId}")
@GET
@Timed
public Object getResults(
@PathParam("experimentId") @NotEmpty long experimentId,
@QueryParam("callback") String callback) {
....
ExperimentResultRepresentation representation = dataSource.queryResults(query);
if (callback != null) {
JSONPObject obj = new JSONPObject(callback, representation);
return obj;
}
return representation;
}
好的是,它没有抛出原始JSON,而是在JSON主体中包含了serializationType
和function
元素:
{
"value": { // the original JSON body }
"serializationType": null,
"function": "jQuery17209002291325014085_1450240336024"
}
我还尝试在方法上方包含@JSONP
注释。也不走运
有什么想法吗?解决了
使用com.fasterxml.jackson.databind.util.JSONPObject
而不是org.codehaus.jackson.map.util.JSONPObject