Se una richiesta viene inviata alla mia API senza un'intestazione Accept, desidero rendere JSON il formato predefinito. Ho due metodi nel mio controller, uno per XML e una per JSON:Come impostare il tipo di contenuto predefinito in Spring MVC in nessuna intestazione Accept è fornito?
@RequestMapping(method = RequestMethod.GET,produces=MediaType.APPLICATION_ATOM_XML_VALUE)
@ResponseBody
public ResponseEntity<SearchResultResource> getXmlData(final HttpServletRequest request) {
//get data, set XML content type in header.
}
@RequestMapping(method = RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public ResponseEntity<Feed> getJsonData(final HttpServletRequest request){
//get data, set JSON content type in header.
}
Quando mando un richiesta senza un header Accept il metodo getXmlData
si chiama, che non è quello che voglio. C'è un modo per dire a Spring MVC di chiamare il metodo getJsonData
se non è stata fornita l'intestazione Accept?
EDIT:
C'è un campo defaultContentType
nel ContentNegotiationManagerFactoryBean
che fa il trucco.
Se hai trovato una soluzione usando 'ContentNegotiationManagerFactoryBean' aggiungilo come soluzione. –