The analysis and solution of this problem on the net is not very deep, most of it can not solve the problem, and the content is basically the same, take doctrine to put the content on his blog! This article will delve into the Spring source code to analyze the root cause of the problem.

Question why

There are two possible reasons for the error:

1. The content-type parameter is not set in the request header, or the content-type parameter is not application/json.

2. The content-type parameter and its value are set correctly in the request header, but there is no processing class for json strings in the project JAR dependencies (pam.xml or build.gradle). Check com. Fasterxml. Jackson. Databind. ObjectMapper and com fasterxml. Jackson. Core. JsonGenerator one does not exist or cannot be loaded, Do not register MappingJackson2HttpMessageConverter, this class will use Jackson json request parameters to the corresponding method; Also check com.google.gson.gson. If it does not exist or cannot be loaded, GsonHttpMessageConverter is not registered. This class uses gson to convert JSON request parameters into corresponding method parameters. If the dependent Jackson and Gson are not added or cannot be loaded, SpringMVC will not find the corresponding argument handling class.

Source code analysis

When using SpringMVC, the < MVC :annotation-driven /> annotation is added, which has a lot of extensibility parameters that can be configured if you are interested. MvcNamespaceHandler {MvcNamespaceHandler}} MvcNamespaceHandler {MvcNamespaceHandler}}

Click “Read the original article” below to see more