当前位置:网站首页>Resolves the interface method that allows annotation requests to be written in postman
Resolves the interface method that allows annotation requests to be written in postman
2022-04-23 18:08:00 【Shallow singing ~ happiness】
1. We like to be in postman Write field comments in You can more intuitively see the meaning of the field as follows :
2. However, if the back-end interface does not do any processing, the following error will be reported :
3. resolvent Add the following configuration to the framework to solve the problem :
package net.longjin.comm.handle; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.fasterxml.jackson.datatype.jsr310.deser.*; import com.fasterxml.jackson.datatype.jsr310.ser.*; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import java.io.Serializable; import java.time.*; import java.time.format.DateTimeFormatter; import java.util.List; /** * author He Zhipeng * CREATED_DATE 2020/4/21 9:49 */ @Configuration public class JsonSerializableConfig implements WebMvcConfigurer { @Bean public MappingJackson2HttpMessageConverter customJackson2HttpMessageConverter() { MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter(); ObjectMapper objectMapper = new ObjectMapper(); // For empty objects, turn json Don't throw errors when objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); // Disable an exception thrown when an unknown property is encountered objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); // Allow comments objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); // serialize BigDecimal Do not use scientific counting to output objectMapper.configure(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN, true); // Date and time formatting JavaTimeModule localDateTime = new JavaTimeModule(); localDateTime.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); localDateTime.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); localDateTime.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); localDateTime.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); localDateTime.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern("HH:mm:ss"))); localDateTime.addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ofPattern("HH:mm:ss"))); localDateTime.addSerializer(MonthDay.class, new MonthDaySerializer(DateTimeFormatter.ofPattern("MM-dd"))); localDateTime.addDeserializer(MonthDay.class, new MonthDayDeserializer(DateTimeFormatter.ofPattern("MM-dd"))); localDateTime.addSerializer(Year.class, new YearSerializer(DateTimeFormatter.ofPattern("yyyy"))); localDateTime.addDeserializer(Year.class, new YearDeserializer(DateTimeFormatter.ofPattern("yyyy"))); localDateTime.addSerializer(YearMonth.class, new YearMonthSerializer(DateTimeFormatter.ofPattern("yyyy-MM"))); localDateTime.addDeserializer(YearMonth.class, new YearMonthDeserializer(DateTimeFormatter.ofPattern("yyyy-MM"))); objectMapper.registerModule(localDateTime); jsonConverter.setObjectMapper(objectMapper); return jsonConverter; } /*@Bean public FilterRegistrationBean mdcFilter() { FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(); filterRegistrationBean.setFilter(new MdcFilter()); filterRegistrationBean.setOrder(99); filterRegistrationBean.addUrlPatterns("/*"); filterRegistrationBean.setName("mdcFilter"); return filterRegistrationBean; }*/ @Override public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { converters.add(customJackson2HttpMessageConverter()); } }
4. Just call it again
版权声明
本文为[Shallow singing ~ happiness]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231800323152.html
边栏推荐
猜你喜欢
.105Location
Implementation of object detection case based on SSD
A few lines of code teach you to crawl lol skin pictures
Go language JSON package usage
Vulnérabilité d'exécution de la commande de fond du panneau de commande JD - freefuck
JD-FreeFuck 京東薅羊毛控制面板 後臺命令執行漏洞
Theory and practice of laser slam in dark blue College - Chapter 2 (odometer calibration)
PowerDesigner various font settings; Preview font setting; SQL font settings
MySQL_01_简单数据检索
Installation du docker redis
随机推荐
Go's gin framework learning
Vulnérabilité d'exécution de la commande de fond du panneau de commande JD - freefuck
How to ensure the security of futures accounts online?
Implementation of image recognition code based on VGg convolutional neural network
JD freefuck Jingdong HaoMao control panel background Command Execution Vulnerability
positioner
Identification verification code
ArcGIS license error -15 solution
Closure type of rust (difference between FN, fnmut and fnone)
Arcpy adds fields and loop assignments to vector data
word frequency count
Notes on common basic usage of eigen Library
Auto.js 自定义对话框
How to install jsonpath package
Calculation of fishing net road density
Qt读写XML文件(含源码+注释)
PowerDesigner various font settings; Preview font setting; SQL font settings
Deep learning classic network analysis and target detection (I): r-cnn
Basic usage of crawler requests
Docker 安裝 Redis