当前位置:网站首页>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
边栏推荐
- Dock installation redis
- MySQL_01_简单数据检索
- Classification of cifar100 data set based on convolutional neural network
- Realsense selection comparison d455 d435i d415 t265 3D hardware comparison
- Go对文件操作
- Installation du docker redis
- C network related operations
- MySQL 中的字符串函数
- Cells in rust share variable pointers
- Docker 安裝 Redis
猜你喜欢
Vulnérabilité d'exécution de la commande de fond du panneau de commande JD - freefuck
C# 网络相关操作
Operators in C language
C#的随机数生成
Clion installation tutorial
C# 的数据流加密与解密
Dock installation redis
Go's gin framework learning
Implementation of image recognition code based on VGg convolutional neural network
Win1远程出现“这可能是由于credssp加密oracle修正”解决办法
随机推荐
Visualization of residential house prices
Rust: a simple example of TCP server and client
Batch export ArcGIS attribute table
Stanford machine learning course summary
Nodejs安装
Classes and objects
Docker 安裝 Redis
GDAL + ogr learning
MySQL_01_简单数据检索
MySQL_ 01_ Simple data retrieval
Notes on common basic usage of eigen Library
Auto.js 自定义对话框
How to read literature
String function in MySQL
word frequency count
_ FindText error
Format problems encountered in word typesetting
What are the relationships and differences between threads and processes
线上怎么确定期货账户安全的?
A few lines of code teach you to crawl lol skin pictures