"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > ## Why Does My Spring JSON Request Result in a 406 (Not Acceptable) Error?

## Why Does My Spring JSON Request Result in a 406 (Not Acceptable) Error?

Published on 2024-11-08
Browse:718

## Why Does My Spring JSON Request Result in a 406 (Not Acceptable) Error?

Resolving Spring JSON Request 406 (Not Acceptable) Error

In the pursuit of troubleshooting the "406 Not Acceptable" error encountered when performing a JSON request in Spring, we delve into the cause and provide a solution.

According to the HTTP response status code definition, this error signifies that the requested resource cannot generate responses with acceptable content characteristics based on the accept headers in the request.

Examining the Code

In your scenario, the request accepts application/json, but the controller lacks the capability to produce responses in that format. Typically, this occurs when the appropriate HTTPMessageConverter is not available to process the @ResponseBody-annotated return value.

HTTPMessageConverters are registered automatically when using and specific third-party libraries are on the classpath.

Solution

To resolve this issue, ensure that you have the correct Jackson library in your classpath:

  • jackson-core-asl-1.7.4.jar
  • jackson-mapper-asl-1.7.4.jar

Additionally, ensure that you have the directive in your configuration.

By implementing these changes, you should be able to successfully make JSON requests and receive responses without encountering the 406 error.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3