0

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

11
  • How are you calling the endpoint? Do you get any exception in your logs? Commented Oct 13, 2021 at 0:06
  • 1
    Did you add an Accept header in your HTTP request? Accept: */* Commented Oct 13, 2021 at 0:09
  • @JoãoDias For Now I'm trying to invoke using Postman with debug mode enabled on my IDE. I can see the control moving without any concerns all the way till the Controller Method exit. The Response Object as well is loaded appropriately. No Exceptions reported in the logs Commented Oct 13, 2021 at 0:23
  • @athom Yes I did try that on Postman. BTW Postman adds it automatically. I did try adding it explicitly and also tried specifying Application/json, nothing worked Commented Oct 13, 2021 at 0:25
  • What if you try something simpler. Something like ResponseEntity<String> instead of ResponseEntity<AnalysisDetailResponse>. This is not what you need but at least we could learn if the issue could be with the serialization of AnalysisDetailResponse. Commented Oct 13, 2021 at 0:38

1 Answer 1

1

Was able to get this working eventually by updating the Response object class's definition. Lombok was been used and I had applied the @Data annotation to the Response class as well as the static inner class. The motive was to club multiple Lombok annotations into one Replacing the @Data annotation with a more verbose set including @NoArgsConstructor, @AllArgsConstructor, @Getter, @Setter resolved the issue.

So, one or more of these Lombok annotations was the real culprit in this scenario: @ToString, @EqualsAndHashCode, @RequiredArgsConstructor

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.