GetMapping, produces and HttpMediaTypeNotAcceptableException

344 Views Asked by At

I am trying to add versioning of my rest endpoints. I was following the tutorial found at https://www.springboottutorial.com/spring-boot-versioning-for-rest-services. I am using spring-boot-starter-parent 2.6.2. I created 2 endpoints:

@GetMapping(value="/student/produces", produces="application/vnd.app-v1+json")
public StudentV1 producesV1() {
  return new StudentV1("AA");
}

@GetMapping(value="/student/produces", produces="application/vnd.app-v2+json")
public StudentV2 producesV2() {
  return new StudentV1(new Name("BB"));
}

Whenever I try to hit the endpoints (either via swagger/OAS3 or curl) I get an HttpMediaTypeNotAcceptableException: Could not find acceptable representation. None of my google-fu has helped.

Any thoughts?

1

There are 1 best solutions below

1
On BEST ANSWER

Fixed it. In our WebMvcConfigurer.configureContentNegotiation we had set contentNegotiationConfigurer.ignoreAcceptHeader to true. Changed it to false and all is good.