From 9b4433fddf5b401edb0aace8a404ac733b122702 Mon Sep 17 00:00:00 2001
From: 田源 <tianyuan@vci-tech.com>
Date: 星期四, 03 四月 2025 14:35:02 +0800
Subject: [PATCH] 添加非密字段显示
---
Source/BladeX-Tool/blade-core-tool/src/main/java/org/springblade/core/tool/config/JacksonConfiguration.java | 82 +++++++++++++++++++++++++++++++++++++++++
1 files changed, 82 insertions(+), 0 deletions(-)
diff --git a/Source/BladeX-Tool/blade-core-tool/src/main/java/org/springblade/core/tool/config/JacksonConfiguration.java b/Source/BladeX-Tool/blade-core-tool/src/main/java/org/springblade/core/tool/config/JacksonConfiguration.java
new file mode 100644
index 0000000..8f47d7d
--- /dev/null
+++ b/Source/BladeX-Tool/blade-core-tool/src/main/java/org/springblade/core/tool/config/JacksonConfiguration.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * Neither the name of the dreamlu.net developer nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * Author: Chill 搴勯獮 (smallchill@163.com)
+ */
+package org.springblade.core.tool.config;
+
+import com.fasterxml.jackson.core.json.JsonReadFeature;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.MapperFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import org.springblade.core.tool.jackson.BladeJacksonProperties;
+import org.springblade.core.tool.jackson.BladeJavaTimeModule;
+import org.springblade.core.tool.utils.DateUtil;
+import org.springframework.boot.autoconfigure.AutoConfiguration;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
+
+import java.text.SimpleDateFormat;
+import java.time.ZoneId;
+import java.util.Locale;
+import java.util.TimeZone;
+
+/**
+ * Jackson閰嶇疆绫�
+ *
+ * @author Chill
+ */
+@AutoConfiguration(before = JacksonAutoConfiguration.class)
+@ConditionalOnClass(ObjectMapper.class)
+@EnableConfigurationProperties(BladeJacksonProperties.class)
+public class JacksonConfiguration {
+
+ @Bean
+ @ConditionalOnMissingBean
+ public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
+ builder.simpleDateFormat(DateUtil.PATTERN_DATETIME);
+ //鍒涘缓ObjectMapper
+ 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(DateUtil.PATTERN_DATETIME, 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(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
+ //鏃ユ湡鏍煎紡鍖�
+ objectMapper.configure(MapperFeature.IGNORE_DUPLICATE_MODULE_REGISTRATIONS, false);
+ objectMapper.registerModule(BladeJavaTimeModule.INSTANCE);
+ objectMapper.configure(MapperFeature.IGNORE_DUPLICATE_MODULE_REGISTRATIONS, true);
+ objectMapper.findAndRegisterModules();
+ return objectMapper;
+ }
+
+}
--
Gitblit v1.9.3