REST. Jersey. How to programmatically choose what type to return: JSON or XML?

后端 未结 3 1628
深忆病人
深忆病人 2021-02-04 11:53

I have 2 questions:

1. Can I create one class, annotate it with JAXB annotations(for XML support) and declare in web.xml

3条回答
  •  迷失自我
    2021-02-04 12:25

    If your client wants to use a part of the URL to configure the response type, you can use a Servlet filter.

    An easy way to implement overriding the representation (media type) could use a URL query parameter:

    /resources/todo?format=json

    The Servlet filter parses the URL query parameters, and if a format=json is present, replaces or adds the accept header "application/json".

提交回复
热议问题