Many times I’ve been asked to provide a set of Web Services interfaces where both JSON and XML clients can communicate with the server. Primarily it’s done for a set of reasons:
- XML is very convenient to use for inter-service communication.
- JSON is great for AJAX (web) clients. It’s perfect for GWT too.
In the recent project we’ve been using XStream for all serialization aspects and, since it can serialize both to XML and JSON, it was plugged into Jersey as a provider too. Following you can see XML and JSON providers implemented using XStream library.
XML Provider (annotated to be a default provider, it’ll be used if no Content-Type or Accept headers provided):



