package com.qianwen.core.tool.config;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
import java.nio.charset.StandardCharsets;
|
import java.util.List;
|
import com.qianwen.core.tool.jackson.BladeJacksonProperties;
|
import com.qianwen.core.tool.jackson.MappingApiJackson2HttpMessageConverter;
|
import org.springframework.context.annotation.Configuration;
|
import org.springframework.core.annotation.Order;
|
import org.springframework.format.FormatterRegistry;
|
import org.springframework.format.datetime.DateFormatter;
|
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
|
import org.springframework.http.converter.HttpMessageConverter;
|
import org.springframework.http.converter.ResourceHttpMessageConverter;
|
import org.springframework.http.converter.ResourceRegionHttpMessageConverter;
|
import org.springframework.http.converter.StringHttpMessageConverter;
|
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
@Configuration(proxyBeanMethods = false)
|
@Order(Integer.MIN_VALUE)
|
/* loaded from: blade-core-tool-9.3.0.0-SNAPSHOT.jar:org/springblade/core/tool/config/MessageConfiguration.class */
|
public class MessageConfiguration implements WebMvcConfigurer {
|
private final ObjectMapper objectMapper;
|
private final BladeJacksonProperties properties;
|
|
public MessageConfiguration(final ObjectMapper objectMapper, final BladeJacksonProperties properties) {
|
this.objectMapper = objectMapper;
|
this.properties = properties;
|
}
|
|
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
converters.removeIf(x -> {
|
return (x instanceof StringHttpMessageConverter) || (x instanceof AbstractJackson2HttpMessageConverter);
|
});
|
converters.add(new ByteArrayHttpMessageConverter());
|
converters.add(new ResourceHttpMessageConverter());
|
converters.add(new ResourceRegionHttpMessageConverter());
|
converters.add(new MappingApiJackson2HttpMessageConverter(this.objectMapper, this.properties));
|
converters.add(new StringHttpMessageConverter(StandardCharsets.UTF_8));
|
}
|
|
public void addFormatters(FormatterRegistry registry) {
|
registry.addFormatter(new DateFormatter("yyyy-MM-dd"));
|
registry.addFormatter(new DateFormatter("yyyy-MM-dd HH:mm:ss"));
|
}
|
}
|