I have a spring controller (MyController) which servers data as json.
With a few configuration changes, I will be able to reuse the same controller and have it serve the same data, but as xml, not json.
I'd love to be able to create myControllerInstanceA, and configure it to use /json as a base url, then create myControllerInstanceB and have it use /xml as a base url.
The only way I can think of to do this is to subclass MyController, and set the subclass's @requestMapping to /xml. I'd rather be able to do some configuration in my springap-servlet.xml to achieve the same effect.
Is this possible?
I'm guessing some of you spring wizards reading this might be thinking "why the heck would he want to do that". So I'll explain the techniques i'm using: I'm creating a controller, which adds simple java beans to a ModelAndView. The controller also ads a view. The view takes the java beans and serializes them to json, or to xml, depending on how the controller was configured. I think there is probably a more Spring-ish way to do this, but this approach seemed simple and straightforward enough. Also, it allows me to work with a JSON library I'm familiar with, rather than the one that Spring seems set up to use. Points for anyone who tells me the Spring way to do it -- how to easily serve the same data as either json or xml, reusing controller code as much as possible.