Dynamically change RESTEasy service return type

瘦欲@ 提交于 2019-12-05 12:39:49

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 })
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!