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:
- Spring jacjson version conflict “nosuchme” thodError:com.fasterxml.jackson.databind.ObjectMapper.canSerialize “
- Using jmh in eclipse
- Springboot integrated with mybatis
- Dependency frame package of Maven Alibaba JSON
- Realization of springboot authorization verification technology based on JWT
- About the steps to create Maven’s (WEB) dependency using in idea
- SLF4J:Failed to load class “org.slf4j.impl.StaticLoggerBinder”
- com.alibaba.fastjson .JSONException: For input string: “3000-01-01” or “9999-12-31”
- Adding fastjson dependency to Maven project
- Spring boot thymeleaf crud implements simple functions of adding, deleting, modifying and querying
- Error parsing lifecycle processing instructions
- Solution of redisconnection factory in springboot2 not Autowired
- Springboot integration redis reports non null key required (solved)
- Related configuration of mybatis project
- Pit encountered by entity class data type BigDecimal
- Idea Maven project uses package to package and report error (package does not exist)
- Struts 2 encapsulates form data into list and map sets
- Java docking PayPal to achieve automatic renewal function
- Kafka connection abnormal org.apache.kafka . common.errors.TimeoutException : Failed to update metadata after 60000 ms.
- Failed to execute goal com.spotify:docker-maven-plugin:1.0.0:build Exception caught: basedir src/mai