Search code examples
javajsonweb-servicescxf

Why RESTful web service choose XML instead of JSON if we give both in produces list?


I have a RESTful web service that produces both XML and JSON. But when I give both in produces list such as

@Produces({"application/json","application/xml"})

It only produces XML when I run it in a browser. So my question does XML is default or high priority than the other ?


Solution

  • You can delete the application/xml since I doubt that you need that and it will return JSON as response even on your browser, but if you really need that application/xml I suggest you to test your REST API using REST Client such as Postman or just simple curl and specify on your header request:

    Content-Type: application/json
    Accept: application/json