开发者

Dynamically change RESTEasy service return type

开发者 https://www.devze.com 2023-01-17 05:29 出处:网络
Am I able to change the value of @Produces annotation parameter in my RESTEasy services?? The task I\'m given is to integrate multiple format reporting to an existing reporting system.

Am I able to change the value of @Produces annotation parameter in my RESTEasy services??

The task I'm given is to integrate multiple format reporting to an existing reporting system. So changing the @Produces annotation parameter dynamically would开发者_如何学编程 help me a lot.

Thanks in advance!


Make your method return a Response object and try something like this;

int status = 200;
String type = MediaType.APPLICATION_XML;
String response = "<hello>world</hello>";
return Response.status(status).type(type).entity(response).build();

I think the type in the response will override what you annotated, but I haven't tested it.


You can specify several entries in @Produces. Your request should mention which format (as mime type) do you want as the result.

Example:

@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
0

精彩评论

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