Reputation: 2353
Another wierd problem of mine. I had controller for rest api:
@RestController()
@RequestMapping("/api/project")
public class ProjectController{
@PreAuthorize("hasAuthority('ROLE_USER')")
@GetMapping(value = "/{id}/severitychart")
public ResponseEntity<HashMap<String,Long>> showSeverityChart(@PathVariable("id")Long id) {
return projectService.showSeverityChart(id);
}
}
and it was working great, returining JSON
response.
Later I had to add proccessing of XML
- nothing fancy just simple parsing of given XML
message and storing it into database. Still all responses should be mapped to JSONit was done using
JAXBContext`
from now on each response of API call return XML structured object with header content-type: application/xml
is it possible to keep service as t is and still use default JSON mapping?
I would like not to put produces = "application/json"
on each endpoint...
Upvotes: 1
Views: 56
Reputation: 821
@EnableWebMvc
@Configuration
public class WebConfiguration implements WebMvcConfigurer {
@Override
public void configureContentNegotiation(final ContentNegotiationConfigurer configurer) {
configurer.defaultContentType(MediaType.APPLICATION_JSON);
}
}
Upvotes: 2