jackson配置
This commit is contained in:
parent
870c1d604e
commit
449e36ab4a
|
|
@ -1,9 +1,15 @@
|
|||
package cn.ysk.cashier.config.interceptor;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* @author lyf
|
||||
*/
|
||||
|
|
@ -13,4 +19,25 @@ public class WebConfig implements WebMvcConfigurer {
|
|||
public void addInterceptors(InterceptorRegistry registry){
|
||||
registry.addInterceptor(new UserInterceptor());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MappingJackson2HttpMessageConverter jackson2HttpMessageConverter() {
|
||||
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
//忽略未知属性
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
|
||||
//日期格式转换
|
||||
//mapper.setDateFormat(new SimpleDateFormat(DateUtils.DATE_TIME_PATTERN));
|
||||
mapper.setTimeZone(TimeZone.getTimeZone("GMT+8"));
|
||||
|
||||
//Long类型转String类型
|
||||
//SimpleModule simpleModule = new SimpleModule();
|
||||
//simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
|
||||
//simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance);
|
||||
//mapper.registerModule(simpleModule);
|
||||
converter.setObjectMapper(mapper);
|
||||
return converter;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue