I am working on a SpringBoot project, that uses the regular MVC mechanism to expose the REST APIs.
In one particular GET API, I am getting 406 HTTP Response.
Here is how my Controller method looks:
@GetMapping(path = "/analysis/detail/{analysisId}")
public ResponseEntity<AnalysisDetailResponse> getAnalysisDetails(
@PathVariable @NotNull Long analysisId) throws BusinessException {
AnalysisDetailResponse analysisDetailResponse = analysisService.getAnalysisDetailsByAnalysisId(analysisId);
// return ResponseEntity.ok(analysisService.getAnalysisDetailsByAnalysisId(analysisId));
return ResponseEntity.ok(analysisDetailResponse);
}
The AnalysisDetailResponse is created using Lombok (which is working flawlessly in case of other APIs)
@Builder
@ToString
public class AnalysisDetailResponse {
@NotNull
private Long id;
@NotNull
private AnalysisStatus state;
private String failedSummary;
@NotNull
@NotEmpty
@Valid
private List<PostDetail> posts;
@Builder
@ToString
private static class PostDetail {
@NotNull
private Long id;
@NotNull
private float score;
@NotNull
private String body;
private List<String> childBodyList;
}
}
I've verified the contents of the entire Response object and it seems to be perfect. However, the response is always 406.
I need the response in JSON format, hence, explicit mentioning of the response type isn't really necessary IMO.
Nevertheless, I tried adding the below content to the @GetMapping annotation, but found no luck:
produces = MediaType.APPLICATION_JSON_VALUE
A majority of relevant posts are suggesting to add the jackson-mapper-asl and jackson-core-asl libraries. I tried it, but that didn't make any difference
Please note, it's just this particular API that's causing issues. There are other APIs defined in the same Controller that are working fine.
Kindly suggest....
Update: I am trying to hit the API using Postman and I did try adding the Accept Header parameter explicitly. No luck with it
Acceptheader in your HTTP request?Accept: */*ResponseEntity<String>instead ofResponseEntity<AnalysisDetailResponse>. This is not what you need but at least we could learn if the issue could be with the serialization ofAnalysisDetailResponse.