@RequestMapping(value = "/user/{username:.+}", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
User user(@PathVariable String username) {
User user = userRepository.findByUsername(username);
if (user == null)
throw new UserNotFoundException("User not found");
return user;
}
This is method representing that action. Controller is annotated with @RestController
Solved
Content type negotiation mechanism should be overriden.
Explonation: http://spring.io/blog/2013/05/11/content-negotiation-using-spring-mvc
Code:
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.mediaType("pl", MediaType.APPLICATION_JSON);
}