| @@ -1,5 +1,7 @@ | |||||
| package com.iformall.config; | 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.ObjectMapper; | ||||
| import com.fasterxml.jackson.databind.module.SimpleModule; | import com.fasterxml.jackson.databind.module.SimpleModule; | ||||
| import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; | 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.BigDecimal; | ||||
| import java.math.BigInteger; | import java.math.BigInteger; | ||||
| import java.text.SimpleDateFormat; | |||||
| import java.util.List; | import java.util.List; | ||||
| @Configuration | @Configuration | ||||
| @EnableWebMvc | @EnableWebMvc | ||||
| public class WebConfig implements WebMvcConfigurer { | public class WebConfig implements WebMvcConfigurer { | ||||
| @Override | @Override | ||||
| public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { | public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { | ||||
| MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter(); | MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter(); | ||||
| //ObjectMapper 是Jackson库的主要类。它提供一些功能将转换成Java对象匹配JSON结构,反之亦然 | //ObjectMapper 是Jackson库的主要类。它提供一些功能将转换成Java对象匹配JSON结构,反之亦然 | ||||
| ObjectMapper objectMapper = new ObjectMapper(); | ObjectMapper objectMapper = new ObjectMapper(); | ||||
| SimpleModule simpleModule = new SimpleModule(); | 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类型 | //序列化将Long转String类型 | ||||
| simpleModule.addSerializer(Long.class, ToStringSerializer.instance); | simpleModule.addSerializer(Long.class, ToStringSerializer.instance); | ||||
| simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); | simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); | ||||
| @@ -1,5 +1,7 @@ | |||||
| package com.iformall.config; | 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.ObjectMapper; | ||||
| import com.fasterxml.jackson.databind.module.SimpleModule; | import com.fasterxml.jackson.databind.module.SimpleModule; | ||||
| import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; | ||||
| @@ -16,6 +18,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | |||||
| import java.math.BigDecimal; | import java.math.BigDecimal; | ||||
| import java.math.BigInteger; | import java.math.BigInteger; | ||||
| import java.text.SimpleDateFormat; | |||||
| import java.util.List; | import java.util.List; | ||||
| /** | /** | ||||
| @@ -58,6 +61,12 @@ public class WebMvcConfig implements WebMvcConfigurer { | |||||
| //ObjectMapper 是Jackson库的主要类。它提供一些功能将转换成Java对象匹配JSON结构,反之亦然 | //ObjectMapper 是Jackson库的主要类。它提供一些功能将转换成Java对象匹配JSON结构,反之亦然 | ||||
| ObjectMapper objectMapper = new ObjectMapper(); | ObjectMapper objectMapper = new ObjectMapper(); | ||||
| SimpleModule simpleModule = new SimpleModule(); | 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类型 | //序列化将Long转String类型 | ||||
| simpleModule.addSerializer(Long.class, ToStringSerializer.instance); | simpleModule.addSerializer(Long.class, ToStringSerializer.instance); | ||||
| simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); | simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); | ||||
| @@ -1,5 +1,7 @@ | |||||
| package com.iformall.config; | 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.ObjectMapper; | ||||
| import com.fasterxml.jackson.databind.module.SimpleModule; | import com.fasterxml.jackson.databind.module.SimpleModule; | ||||
| import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; | ||||
| @@ -16,6 +18,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | |||||
| import java.math.BigDecimal; | import java.math.BigDecimal; | ||||
| import java.math.BigInteger; | import java.math.BigInteger; | ||||
| import java.text.SimpleDateFormat; | |||||
| import java.util.List; | import java.util.List; | ||||
| /** | /** | ||||
| @@ -58,6 +61,12 @@ public class WebMvcConfig implements WebMvcConfigurer { | |||||
| //ObjectMapper 是Jackson库的主要类。它提供一些功能将转换成Java对象匹配JSON结构,反之亦然 | //ObjectMapper 是Jackson库的主要类。它提供一些功能将转换成Java对象匹配JSON结构,反之亦然 | ||||
| ObjectMapper objectMapper = new ObjectMapper(); | ObjectMapper objectMapper = new ObjectMapper(); | ||||
| SimpleModule simpleModule = new SimpleModule(); | 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类型 | //序列化将Long转String类型 | ||||
| simpleModule.addSerializer(Long.class, com.fasterxml.jackson.databind.ser.std.ToStringSerializer.instance); | simpleModule.addSerializer(Long.class, com.fasterxml.jackson.databind.ser.std.ToStringSerializer.instance); | ||||
| simpleModule.addSerializer(Long.TYPE, com.fasterxml.jackson.databind.ser.std.ToStringSerializer.instance); | simpleModule.addSerializer(Long.TYPE, com.fasterxml.jackson.databind.ser.std.ToStringSerializer.instance); | ||||