dropwizard: produce both html and json from the same class

瘦欲@ 提交于 2019-12-06 13:31:41

You'll need to annotate the resources as providing both HTML and JSON:

@Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON})

Then just make sure you have MessageBodyWriter implementations registered to handle the method's return type. Dropwizard's JacksonMessageBodyProvider should handle the JSON; if you're using Dropwizard Views, ViewMessageBodyWriter should handle the rest. Jersey will do the content negotiation with the client, provided your client has application/json in the request's Accept header.

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