package com.se.simu.config;
|
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
import com.alibaba.fastjson.support.config.FastJsonConfig;
|
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
import org.springframework.context.annotation.Configuration;
|
import org.springframework.http.MediaType;
|
import org.springframework.http.converter.HttpMessageConverter;
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
|
import java.nio.charset.StandardCharsets;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
@Configuration
|
@SuppressWarnings("ALL")
|
public class WebConfig extends WebMvcConfigurationSupport {
|
@Override
|
protected void addCorsMappings(CorsRegistry registry) {
|
registry.addMapping("/**")
|
//.allowCredentials(true)
|
.allowedHeaders("*")
|
.allowedOrigins("*")
|
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
|
.allowCredentials(true)
|
.maxAge(3600);
|
}
|
|
@Override
|
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
|
FastJsonConfig config = new FastJsonConfig();
|
config.setSerializerFeatures(
|
SerializerFeature.WriteNullListAsEmpty,
|
SerializerFeature.WriteMapNullValue,
|
SerializerFeature.WriteNullStringAsEmpty,
|
SerializerFeature.WriteNullNumberAsZero,
|
SerializerFeature.WriteNullBooleanAsFalse);
|
//SerializerFeature.PrettyFormat);
|
|
List<MediaType> supportedMediaTypes = new ArrayList<>();
|
supportedMediaTypes.add(MediaType.APPLICATION_JSON);
|
// supportedMediaTypes.add(MediaType.APPLICATION_JSON_UTF8)
|
supportedMediaTypes.add(MediaType.APPLICATION_ATOM_XML);
|
supportedMediaTypes.add(MediaType.APPLICATION_FORM_URLENCODED);
|
supportedMediaTypes.add(MediaType.APPLICATION_OCTET_STREAM);
|
supportedMediaTypes.add(MediaType.APPLICATION_PDF);
|
supportedMediaTypes.add(MediaType.APPLICATION_RSS_XML);
|
supportedMediaTypes.add(MediaType.APPLICATION_XHTML_XML);
|
supportedMediaTypes.add(MediaType.APPLICATION_XML);
|
supportedMediaTypes.add(MediaType.IMAGE_GIF);
|
supportedMediaTypes.add(MediaType.IMAGE_JPEG);
|
supportedMediaTypes.add(MediaType.IMAGE_PNG);
|
supportedMediaTypes.add(MediaType.TEXT_EVENT_STREAM);
|
supportedMediaTypes.add(MediaType.TEXT_HTML);
|
supportedMediaTypes.add(MediaType.TEXT_MARKDOWN);
|
supportedMediaTypes.add(MediaType.TEXT_PLAIN);
|
supportedMediaTypes.add(MediaType.TEXT_XML);
|
converter.setSupportedMediaTypes(supportedMediaTypes);
|
|
converter.setFastJsonConfig(config);
|
converter.setDefaultCharset(StandardCharsets.UTF_8);
|
converters.add(converter);
|
}
|
}
|