Spring MVC 406 status code / could not find acceptable representation

 
Jackson-core-asl-1.9.12.jar Jackson-mapper-asl-1.9.12.jar
The test is not for this error and does not have to rely on the two JARs.
The following configuration returns data normally
 
pom.xml
 

        <!-- Jackson JSON Processor -->

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>${jackson.version}</version>
        </dependency>

 
 
For springMvc. In the XML
 
 

    <mvc:annotation-driven>
        <mvc:message-converters register-defaults="false">
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>text/html;charset=utf-8</value>
                        <value>text/xml;charset=utf-8</value>
                        <value>text/plain;</value>
                        <value>text/json;charset=utf-8</value>
                        <value>application/json;charset=UTF-8</value>
                    </list>
                </property>
            </bean>
            <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
        </mvc:message-converters>
    </mvc:annotation-driven>

 
 
 
 
 
In the Controller
 

  @RequestMapping(value = "checkLogin", method = RequestMethod.POST)
    @ResponseBody
    public ResultDto checkLogin(String name, String password, int role) {

        return loginService.checkLogin(name, password, role);
    }

 
 
 
——————————————————————————-
The ResultDTO object is missing some of the GET methods, causing an error in formatting the JSON object.
Remove the above two JARs and test with the GET method of the returned object, reporting 406 error code.
The debug code in ServletInvocableHandlerMethod. Catch exceptions in the class “Could not find acceptable representation.” ”
After adding the get method, the test returns the JSON character of the object normally
 
 

public class ResultDto {

    private boolean succeed;
    private Object data;

    public ResultDto(boolean succeed) {
        this.succeed = succeed;
    }

    public ResultDto(boolean succeed, Object data) {
        this.succeed = succeed;
        this.data = data;
    }

/*
    public boolean isSucceed() {
        return succeed;
    }

    public Object getData() {
        return data;
    }
*/

    public void setSucceed(boolean succeed) {
        this.succeed = succeed;
    }

    public void setData(Object data) {
        this.data = data;
    }
}

 
 

 

Read More: