Create a text/plain Jersey response

后端 未结 2 785
心在旅途
心在旅途 2020-12-17 02:08

I have some code that works, but I am looking for a better way to do it. I have a RESTful web API that I want to support JSON, XML, and TEXT media types. The JSON and XML

2条回答
  •  独厮守ぢ
    2020-12-17 02:35

    Implementing a MessageBodyReader/Writer would be what you need to do in order to do the following:

    @GET @Path("details/")
    @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN })
    public List details() {
        return manager.details();
    }
    

    It's not very much code to write, and if you are able to write it generic enough you will be able to get some re-use out of it.

提交回复
热议问题