package com.qianwen.core.tool.config;
|
|
import com.fasterxml.jackson.core.json.JsonReadFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
import java.text.SimpleDateFormat;
|
import java.time.ZoneId;
|
import java.util.Locale;
|
import java.util.TimeZone;
|
import com.qianwen.core.tool.jackson.BladeJacksonProperties;
|
import com.qianwen.core.tool.jackson.BladeJavaTimeModule;
|
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Primary;
|
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
|
@AutoConfigureBefore({JacksonAutoConfiguration.class})
|
@EnableConfigurationProperties({BladeJacksonProperties.class})
|
@Configuration(proxyBeanMethods = false)
|
@ConditionalOnClass({ObjectMapper.class})
|
/* loaded from: blade-core-tool-9.3.0.0-SNAPSHOT.jar:org/springblade/core/tool/config/JacksonConfiguration.class */
|
public class JacksonConfiguration {
|
@Bean
|
@Primary
|
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
|
builder.simpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
|
objectMapper.setLocale(Locale.CHINA);
|
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
objectMapper.setTimeZone(TimeZone.getTimeZone(ZoneId.systemDefault()));
|
objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA));
|
objectMapper.configure(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS.mappedFeature(), true);
|
objectMapper.configure(JsonReadFeature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER.mappedFeature(), true);
|
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
|
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
objectMapper.configure(JsonReadFeature.ALLOW_SINGLE_QUOTES.mappedFeature(), true);
|
objectMapper.getDeserializationConfig().withoutFeatures(new DeserializationFeature[]{DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES});
|
objectMapper.registerModule(BladeJavaTimeModule.INSTANCE);
|
objectMapper.findAndRegisterModules();
|
return objectMapper;
|
}
|
}
|