PC
2024-03-31 608f20e0d5d8f95d9bbb917e95e2913682deb77d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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"));
    }
}