动态更改 RESTEasy 服务返回类型 [英] Dynamically change RESTEasy service return type

查看:27
本文介绍了动态更改 RESTEasy 服务返回类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在我的 RESTEasy 服务中更改 @Produces 注释参数的值吗??
我的任务是将多种格式的报告集成到现有的报告系统中.因此,动态更改 @Produces 注释参数会对我有很大帮助.
提前致谢!

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!

推荐答案

让你的方法返回一个 Response 对象并尝试这样的事情;

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.

这篇关于动态更改 RESTEasy 服务返回类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆