Environment: springboot 2.0 9 (this problem does not exist in the latest version of springboot)
Problem Description:
Prompt when post requests @requestbody to receive objects
org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unrecognized field "aaaaa" (class com.ex.application.model.RiskAudit), not marked as ignorable; nested exception is com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "aaaaa" (class com.ex.application.model.RiskAudit), not marked as ignorable (25 known properties: "xxx"])
at [Source: (PushbackInputStream); line: 4, column: 15] (through reference chain: com.ex.application.model.RiskAudit["aaaaa"])
AAAAA is not a property of the riskaudit object
Problem Fix:
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Autowired
private Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder;
/**
* Ignore unmatched properties or add @JsonIgnoreProperties(ignoreUnknown = true) annotation to the response object
* @param converters
*/
@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
converter.setObjectMapper(objectMapper);
return converter;
}
/**
* Format the date (I used LocalDateTime locally, LocalDateTime will become an object when data is obtained without this method)
* @param converters
*/
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
ObjectMapper mapper = jackson2ObjectMapperBuilder.build();
mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
converters.add(0, new MappingJackson2HttpMessageConverter(mapper));
}
}
Read More:
- [Solved] org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot
- org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deseria
- [Solved] Feign Call Port Error: HttpMessageNotReadableException:JSON parse error:Illegal character ((CTRL-CHAR, code 31)
- [Solved] SpringBoot Date Convert Error: JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime`
- [Solved] JSON parse error: Cannot construct instance of
- JSON parse error: invalid UTF-8 solution series [How to Solve]
- [Solved] JSON parse error: Cannot deserialize instance of `java.util.ArrayList<..> out of START_OBJECT token;
- [Solved] SpringBoot Error: org.springframework.http.converter.HttpMessageNotReadableException
- OpenFeign Error: {“code“:1,“msg“:“JSON parse error: Illegal character ((CTRL-CHAR, code 31))
- Fastjson Error: Error: Cannot create inner bean ‘org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
- How to Solve SSM JSON Chinese Messy Code Issue
- [Solved] ES Error: request contains unrecognized parameter [ignore_throttled]
- [Solved] springsecurity custom exceptions: Error: Parse Error: Response overflow
- [Solved] SpringBoot Project Startup Error: Field userMapper in com.demo.controller.MemberController required a bean of type ‘c
- [Tomcat] Unrecognized Windows Sockets error: 10106: Socket creation failed
- [Solved] Windows Start RocketMq Error: Unrecognized VM option ‘UseCMSCompactAtFullCollection‘
- [Solved] Error attempting to get column ‘xxxx_time‘ from result set. Cause: java.sql.SQLFeatureNotSupportedEx
- [Solved] Error creating bean with name ‘accountService‘: Unsatisfied dependency expressed through field
- Ruoyi-cloud Integrated mybatis-plus Error: Unknown column ‘search_value‘ in ‘field list‘
- [Solved] Unsatisfied dependency expressed through field ‘restTemplate’;