|
|
|
@@ -1,5 +1,7 @@ |
|
|
|
package com.iformall.config; |
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.DeserializationConfig; |
|
|
|
import com.fasterxml.jackson.databind.DeserializationFeature; |
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import com.fasterxml.jackson.databind.module.SimpleModule; |
|
|
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; |
|
|
|
@@ -11,19 +13,26 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.BigInteger; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
@Configuration |
|
|
|
@EnableWebMvc |
|
|
|
public class WebConfig implements WebMvcConfigurer { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { |
|
|
|
MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter(); |
|
|
|
//ObjectMapper 是Jackson库的主要类。它提供一些功能将转换成Java对象匹配JSON结构,反之亦然 |
|
|
|
ObjectMapper objectMapper = new ObjectMapper(); |
|
|
|
SimpleModule simpleModule = new SimpleModule(); |
|
|
|
|
|
|
|
DeserializationConfig dc = objectMapper.getDeserializationConfig(); |
|
|
|
// 设置反序列化日期格式、忽略不存在get、set的属性 |
|
|
|
objectMapper.setConfig( |
|
|
|
dc.with(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")) |
|
|
|
.without(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) |
|
|
|
); |
|
|
|
|
|
|
|
//序列化将Long转String类型 |
|
|
|
simpleModule.addSerializer(Long.class, ToStringSerializer.instance); |
|
|
|
simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); |
|
|
|
|