v5.4.3
This commit is contained in:
+2
-2
@@ -16,10 +16,10 @@
|
|||||||
# ProjectName mingli-utils
|
# ProjectName mingli-utils
|
||||||
# ModuleName mingli-utils
|
# ModuleName mingli-utils
|
||||||
# CurrentFile gradle.properties
|
# CurrentFile gradle.properties
|
||||||
# LastUpdate 2026-11-07 13:47:56
|
# LastUpdate 2026-11-09 19:49:52
|
||||||
# UpdateUser MingLiPro
|
# UpdateUser MingLiPro
|
||||||
#
|
#
|
||||||
JDKVERSIONS=17
|
JDKVERSIONS=17
|
||||||
GROUPSID=com.mingliqiye.utils
|
GROUPSID=com.mingliqiye.utils
|
||||||
ARTIFACTID=mingli-utils
|
ARTIFACTID=mingli-utils
|
||||||
VERSIONS=5.4.2
|
VERSIONS=5.4.3
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile OkHttpUtils.kt
|
* CurrentFile OkHttpUtils.kt
|
||||||
* LastUpdate 2026-11-07 13:44:21
|
* LastUpdate 2026-11-09 19:18:03
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
@file:JvmName("OkHttpUtils")
|
@file:JvmName("OkHttpUtils")
|
||||||
@@ -298,3 +298,8 @@ enum class Method {
|
|||||||
/** QUERY 方法(HTTP 扩展方法,需服务端支持)。 */
|
/** QUERY 方法(HTTP 扩展方法,需服务端支持)。 */
|
||||||
QUERY,
|
QUERY,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun Request.Builder.post() = post(RequestBody.EMPTY)
|
||||||
|
fun Request.Builder.put() = put(RequestBody.EMPTY)
|
||||||
|
fun Request.Builder.patch() = patch(RequestBody.EMPTY)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile DateTimeJsonConverter.kt
|
* CurrentFile DateTimeJsonConverter.kt
|
||||||
* LastUpdate 2026-02-07 22:13:41
|
* LastUpdate 2026-11-09 14:35:06
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2026 mingliqiye
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* ProjectName mingli-utils
|
||||||
|
* ModuleName mingli-utils.main
|
||||||
|
* CurrentFile NetworkEndpointJsonConverter.kt
|
||||||
|
* LastUpdate 2026-11-09 14:36:36
|
||||||
|
* UpdateUser MingLiPro
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.mingliqiye.utils.json.converters
|
||||||
|
|
||||||
|
import com.mingliqiye.utils.json.api.type.JsonTypeReference
|
||||||
|
import com.mingliqiye.utils.json.converters.NetworkEndpointJsonConverter.Companion.getJsonConverter
|
||||||
|
import com.mingliqiye.utils.json.converters.base.AnnotationGetter
|
||||||
|
import com.mingliqiye.utils.json.converters.base.BaseJsonStringConverter
|
||||||
|
import com.mingliqiye.utils.network.NetworkEndpoint
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [NetworkEndpoint] 的 JSON 字符串转换器。
|
||||||
|
*
|
||||||
|
* 继承 [BaseJsonStringConverter],负责在网络端点对象与 JSON 字符串之间进行转换:
|
||||||
|
* 序列化时输出形如 `host:port` 的字符串,反序列化时将 `host:port` 字符串还原为
|
||||||
|
* [NetworkEndpoint] 实例。
|
||||||
|
*
|
||||||
|
* 本类为单例:构造器私有,通过 [getJsonConverter] 获取全局共享实例,
|
||||||
|
* 避免在序列化框架中重复创建。
|
||||||
|
*
|
||||||
|
* @see BaseJsonStringConverter
|
||||||
|
* @see NetworkEndpoint
|
||||||
|
*/
|
||||||
|
class NetworkEndpointJsonConverter private constructor() : BaseJsonStringConverter<NetworkEndpoint> {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val networkEndpointJsonConverter by lazy {
|
||||||
|
NetworkEndpointJsonConverter()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 [NetworkEndpointJsonConverter] 的全局单例。
|
||||||
|
*
|
||||||
|
* @return 共享的转换器实例。
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun getJsonConverter(): NetworkEndpointJsonConverter = networkEndpointJsonConverter
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 [NetworkEndpoint] 序列化为 JSON 字符串。
|
||||||
|
*
|
||||||
|
* 输出格式为 `host:port`,由 [NetworkEndpoint.toHostPortString] 生成。
|
||||||
|
*
|
||||||
|
* @param obj 待序列化的网络端点,可能为 `null`。
|
||||||
|
* @param annotationGetter 注解信息提供者,用于在需要时读取格式化相关注解;
|
||||||
|
* 当前实现不依赖注解,保留该参数以符合转换器契约。
|
||||||
|
* @return 序列化后的 `host:port` 字符串;当 [obj] 为 `null` 时返回 `null`。
|
||||||
|
* @throws Exception 若序列化过程中发生异常。
|
||||||
|
*/
|
||||||
|
@Throws(Exception::class)
|
||||||
|
override fun convert(obj: NetworkEndpoint?, annotationGetter: AnnotationGetter): String? {
|
||||||
|
return obj?.let(NetworkEndpoint::toHostPortString)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 JSON 字符串反序列化为 [NetworkEndpoint]。
|
||||||
|
*
|
||||||
|
* 期望输入为 `host:port` 形式的字符串,由 [NetworkEndpoint.Companion.of] 解析。
|
||||||
|
*
|
||||||
|
* @param obj 待反序列化的字符串,可能为 `null`。
|
||||||
|
* @param annotationGetter 注解信息提供者,用于在需要时读取解析相关注解;
|
||||||
|
* 当前实现不依赖注解,保留该参数以符合转换器契约。
|
||||||
|
* @return 解析得到的 [NetworkEndpoint];当 [obj] 为 `null` 时返回 `null`。
|
||||||
|
* @throws Exception 若字符串格式非法或解析过程中发生异常。
|
||||||
|
*/
|
||||||
|
@Throws(Exception::class)
|
||||||
|
override fun deConvert(obj: String?, annotationGetter: AnnotationGetter): NetworkEndpoint? {
|
||||||
|
return obj?.let(NetworkEndpoint.Companion::of)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取本转换器支持的目标类型引用。
|
||||||
|
*
|
||||||
|
* @return 指向 [NetworkEndpoint] 的 [JsonTypeReference]。
|
||||||
|
* @throws Exception 若获取类型引用时发生异常。
|
||||||
|
*/
|
||||||
|
@Throws(Exception::class)
|
||||||
|
override fun getFromType(): JsonTypeReference<NetworkEndpoint> = JsonTypeReference.Companion.of()
|
||||||
|
}
|
||||||
+49
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2026 mingliqiye
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* ProjectName mingli-utils
|
||||||
|
* ModuleName mingli-utils.main
|
||||||
|
* CurrentFile JSONAAutoConfiguration.kt
|
||||||
|
* LastUpdate 2026-11-09 14:59:49
|
||||||
|
* UpdateUser MingLiPro
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.mingliqiye.utils.springboot.autoconfigure
|
||||||
|
|
||||||
|
import com.mingliqiye.utils.json.api.JSONA
|
||||||
|
import com.mingliqiye.utils.json.api.base.JsonApi
|
||||||
|
import com.mingliqiye.utils.logger.MingLiLoggerFactory
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfiguration
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean
|
||||||
|
|
||||||
|
|
||||||
|
@AutoConfiguration
|
||||||
|
@AutoConfigureAfter(name = ["com.mingliqiye.utils.springboot.autoconfigure.JacksonJsonApiAutoConfiguration", "com.mingliqiye.utils.springboot.autoconfigure.Jackson3JsonApiAutoConfiguration"])
|
||||||
|
@ConditionalOnBean(JsonApi::class)
|
||||||
|
open class JSONAAutoConfiguration(
|
||||||
|
jsonApi: JsonApi,
|
||||||
|
) {
|
||||||
|
val log = MingLiLoggerFactory.getLogger<JSONAAutoConfiguration>()
|
||||||
|
|
||||||
|
init {
|
||||||
|
JSONA.setJsonApi(jsonApi)
|
||||||
|
log.info(
|
||||||
|
"JSONA use ${
|
||||||
|
jsonApi.javaClass
|
||||||
|
}"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
+21
-30
@@ -13,19 +13,20 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ProjectName FastBaseMapper.kt
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile Jackson3AutoConfiguration.kt
|
* CurrentFile Jackson3AutoConfiguration.kt
|
||||||
* LastUpdate 2026-10-26 23:22:18
|
* LastUpdate 2026-11-09 14:18:45
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.mingliqiye.utils.springboot.autoconfigure;
|
package com.mingliqiye.utils.springboot.autoconfigure;
|
||||||
|
|
||||||
import com.mingliqiye.utils.json.converters.DateTimeJsonConverter
|
|
||||||
import com.mingliqiye.utils.json.converters.UUIDJsonConverter
|
|
||||||
import com.mingliqiye.utils.json.converters.base.getJackson3Module
|
import com.mingliqiye.utils.json.converters.base.getJackson3Module
|
||||||
import com.mingliqiye.utils.logger.MingLiLoggerFactory
|
import com.mingliqiye.utils.logger.MingLiLoggerFactory
|
||||||
|
import com.mingliqiye.utils.springboot.autoconfigure.builder.JacksonBuilder
|
||||||
|
import com.mingliqiye.utils.springboot.autoconfigure.builder.JacksonJsonBuilderImpl
|
||||||
|
import org.springframework.beans.factory.ObjectProvider
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
||||||
@@ -36,37 +37,27 @@ import org.springframework.context.annotation.Bean
|
|||||||
@AutoConfigureAfter(name = ["org.springframework.boot.jackson.autoconfigure.JacksonAutoConfiguration"])
|
@AutoConfigureAfter(name = ["org.springframework.boot.jackson.autoconfigure.JacksonAutoConfiguration"])
|
||||||
open class Jackson3AutoConfiguration {
|
open class Jackson3AutoConfiguration {
|
||||||
|
|
||||||
private val logger = MingLiLoggerFactory.getLogger<Jackson3AutoConfiguration>()
|
private val log = MingLiLoggerFactory.getLogger<Jackson3AutoConfiguration>()
|
||||||
|
|
||||||
/**
|
|
||||||
* 注册 UUID 的 Jackson 3 序列化/反序列化模块。
|
|
||||||
*
|
|
||||||
* 如需替换 UUID 处理逻辑,注册名为 [UUIDJsonConverterJsonMapperCustomizer]
|
|
||||||
* 的 [JsonMapperBuilderCustomizer] Bean 即可,本 Bean 将自动跳过。
|
|
||||||
*/
|
|
||||||
@Bean("UUIDJsonConverterJsonMapperCustomizer")
|
@Bean("UUIDJsonConverterJsonMapperCustomizer")
|
||||||
@ConditionalOnMissingBean(name = ["UUIDJsonConverterJsonMapperCustomizer"])
|
@ConditionalOnMissingBean(name = ["UUIDJsonConverterJsonMapperCustomizer"])
|
||||||
open fun getUUIDJsonConverterJsonMapperCustomizer(): JsonMapperBuilderCustomizer {
|
fun jsonMapperBuilderCustomizer(builders: ObjectProvider<JacksonBuilder>): JsonMapperBuilderCustomizer {
|
||||||
return JsonMapperBuilderCustomizer { builder ->
|
val builderList = builders.orderedStream().toList()
|
||||||
builder.addModule(UUIDJsonConverter.getJsonConverter().getJackson3Module())
|
var jacksonJsonBuilderImpl = JacksonJsonBuilderImpl()
|
||||||
}.also {
|
log.info("scan ${builderList.size} JacksonBuilders")
|
||||||
logger.info("MingliUtils Jackson3 UUID Serializers created")
|
builderList.forEach {
|
||||||
|
jacksonJsonBuilderImpl = it.customize(jacksonJsonBuilderImpl) as JacksonJsonBuilderImpl
|
||||||
}
|
}
|
||||||
|
return JsonMapperBuilderCustomizer {
|
||||||
|
it.addModules(
|
||||||
|
*jacksonJsonBuilderImpl.getData().map { converter ->
|
||||||
|
converter.getJackson3Module().also { module ->
|
||||||
|
log.info("Jackson3 Module Install ${module.moduleName}")
|
||||||
|
}
|
||||||
|
}.toTypedArray()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 注册日期时间的 Jackson 3 序列化/反序列化模块。
|
|
||||||
*
|
|
||||||
* 如需替换日期时间处理逻辑,注册名为 [DateTimeJsonConverterJsonMapperCustomizer]
|
|
||||||
* 的 [JsonMapperBuilderCustomizer] Bean 即可,本 Bean 将自动跳过。
|
|
||||||
*/
|
|
||||||
@Bean("DateTimeJsonConverterJsonMapperCustomizer")
|
|
||||||
@ConditionalOnMissingBean(name = ["DateTimeJsonConverterJsonMapperCustomizer"])
|
|
||||||
open fun getDateTimeJsonConverterJsonMapperCustomizer(): JsonMapperBuilderCustomizer {
|
|
||||||
return JsonMapperBuilderCustomizer { builder ->
|
|
||||||
builder.addModule(DateTimeJsonConverter.getJsonConverter().getJackson3Module())
|
|
||||||
}.also {
|
|
||||||
logger.info("MingliUtils Jackson3 DateTime Serializers created")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-35
@@ -16,7 +16,7 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile Jackson3JsonApiAutoConfiguration.kt
|
* CurrentFile Jackson3JsonApiAutoConfiguration.kt
|
||||||
* LastUpdate 2026-11-07 13:59:11
|
* LastUpdate 2026-11-09 13:45:29
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -26,11 +26,11 @@ import com.mingliqiye.utils.exception.JsonException
|
|||||||
import com.mingliqiye.utils.json.api.JSONA
|
import com.mingliqiye.utils.json.api.JSONA
|
||||||
import com.mingliqiye.utils.json.api.Jackson3JsonApi
|
import com.mingliqiye.utils.json.api.Jackson3JsonApi
|
||||||
import com.mingliqiye.utils.json.api.base.JsonApi
|
import com.mingliqiye.utils.json.api.base.JsonApi
|
||||||
import com.mingliqiye.utils.logger.MingLiLoggerFactory
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
||||||
import org.springframework.context.annotation.Bean
|
import org.springframework.context.annotation.Bean
|
||||||
|
import org.springframework.context.annotation.Primary
|
||||||
import tools.jackson.databind.json.JsonMapper
|
import tools.jackson.databind.json.JsonMapper
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,43 +65,12 @@ import tools.jackson.databind.json.JsonMapper
|
|||||||
@ConditionalOnClass(name = ["tools.jackson.databind.json.JsonMapper", "org.springframework.boot.jackson.autoconfigure.JacksonAutoConfiguration"])
|
@ConditionalOnClass(name = ["tools.jackson.databind.json.JsonMapper", "org.springframework.boot.jackson.autoconfigure.JacksonAutoConfiguration"])
|
||||||
@AutoConfigureAfter(name = ["com.mingliqiye.utils.springboot.autoconfigure.Jackson3AutoConfiguration"])
|
@AutoConfigureAfter(name = ["com.mingliqiye.utils.springboot.autoconfigure.Jackson3AutoConfiguration"])
|
||||||
open class Jackson3JsonApiAutoConfiguration {
|
open class Jackson3JsonApiAutoConfiguration {
|
||||||
|
@Bean("jackson3JsonApi")
|
||||||
companion object {
|
@Primary
|
||||||
private val logger = MingLiLoggerFactory.getLogger<Jackson3JsonApiAutoConfiguration>()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建并注册默认的 [JsonApi] Bean。
|
|
||||||
*
|
|
||||||
* 使用容器中的 [JsonMapper] 构造 [Jackson3JsonApi]。读取器直接返回该 [JsonMapper];
|
|
||||||
* 写入器被设计为抛出 [JsonException],即本实现不允许通过 [JsonApi] 替换底层
|
|
||||||
* `JsonMapper`,底层实例由 Spring 容器统一管理。
|
|
||||||
*
|
|
||||||
* 创建完成后会尝试初始化全局 [JSONA]:
|
|
||||||
* - 若 [JSONA] 尚未设置,则设置为本实例;
|
|
||||||
* - 若已设置,则保留既有实现。
|
|
||||||
*
|
|
||||||
* 该 Bean 仅在容器中不存在其他 [JsonApi] 时创建。
|
|
||||||
*
|
|
||||||
* @param jsonMapper 容器中的 Jackson 3 映射器
|
|
||||||
* @return 基于 Jackson 3 的 JSON 访问门面
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnMissingBean(JsonApi::class)
|
@ConditionalOnMissingBean(JsonApi::class)
|
||||||
open fun jsonApi(jsonMapper: JsonMapper): JsonApi {
|
open fun jsonApi(jsonMapper: JsonMapper): JsonApi {
|
||||||
return Jackson3JsonApi(
|
return Jackson3JsonApi(
|
||||||
get = { jsonMapper },
|
get = { jsonMapper },
|
||||||
set = { throw JsonException("JSON API set method is not allowed.") })
|
set = { throw JsonException("JSON API set method is not allowed.") })
|
||||||
.also {
|
|
||||||
logger.info("JsonApi Bean Auto Configuration Success")
|
|
||||||
try {
|
|
||||||
JSONA.jsonApi
|
|
||||||
} catch (_: NullPointerException) {
|
|
||||||
JSONA.setJsonApi(it)
|
|
||||||
logger.info(
|
|
||||||
"JSONA Using {}", it.javaClass.name
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-32
@@ -16,23 +16,19 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile JacksonJsonApiAutoConfiguration.kt
|
* CurrentFile JacksonJsonApiAutoConfiguration.kt
|
||||||
* LastUpdate 2026-11-07 13:59:41
|
* LastUpdate 2026-11-09 13:45:41
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.mingliqiye.utils.springboot.autoconfigure
|
package com.mingliqiye.utils.springboot.autoconfigure
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
import com.mingliqiye.utils.json.api.JSONA
|
|
||||||
import com.mingliqiye.utils.json.api.JacksonJsonApi
|
import com.mingliqiye.utils.json.api.JacksonJsonApi
|
||||||
import com.mingliqiye.utils.json.api.base.JsonApi
|
import com.mingliqiye.utils.json.api.base.JsonApi
|
||||||
import com.mingliqiye.utils.logger.MingLiLoggerFactory
|
|
||||||
import org.slf4j.Logger
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
||||||
import org.springframework.context.annotation.Bean
|
import org.springframework.context.annotation.Bean
|
||||||
import org.springframework.context.annotation.Primary
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* JacksonAutoConfiguration 是一个 Spring Boot 自动配置类,用于配置 Jackson 相关的序列化和反序列化功能。
|
* JacksonAutoConfiguration 是一个 Spring Boot 自动配置类,用于配置 Jackson 相关的序列化和反序列化功能。
|
||||||
@@ -44,34 +40,9 @@ import org.springframework.context.annotation.Primary
|
|||||||
@ConditionalOnClass(name = ["com.fasterxml.jackson.databind.ObjectMapper", "org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration"])
|
@ConditionalOnClass(name = ["com.fasterxml.jackson.databind.ObjectMapper", "org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration"])
|
||||||
@AutoConfigureAfter(name = ["com.mingliqiye.utils.springboot.autoconfigure.JacksonJsonAutoConfiguration"])
|
@AutoConfigureAfter(name = ["com.mingliqiye.utils.springboot.autoconfigure.JacksonJsonAutoConfiguration"])
|
||||||
open class JacksonJsonApiAutoConfiguration {
|
open class JacksonJsonApiAutoConfiguration {
|
||||||
|
@Bean("jacksonJsonApi")
|
||||||
|
|
||||||
companion object {
|
|
||||||
private val log: Logger = MingLiLoggerFactory.getLogger("MingliUtils-JacksonAutoConfiguration")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 创建并返回一个 JsonApi Bean 实例。
|
|
||||||
* 该方法会在没有其他 JsonApi Bean 存在时被调用,并将创建的 JacksonJsonApi 实例设置为全局默认的 JSON API。
|
|
||||||
*
|
|
||||||
* @param objectMapper 用于 JSON 操作的 ObjectMapper 实例。
|
|
||||||
* @return 返回配置好的 JsonApi 实例。
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
@Primary
|
|
||||||
@ConditionalOnMissingBean(JsonApi::class)
|
@ConditionalOnMissingBean(JsonApi::class)
|
||||||
open fun jsonApi(objectMapper: ObjectMapper): JsonApi {
|
open fun jsonApi(objectMapper: ObjectMapper): JsonApi {
|
||||||
return JacksonJsonApi(objectMapper).also {
|
return JacksonJsonApi(objectMapper)
|
||||||
log.info("JsonApi Bean Auto Configuration Success")
|
|
||||||
try {
|
|
||||||
JSONA.jsonApi
|
|
||||||
} catch (_: NullPointerException) {
|
|
||||||
JSONA.setJsonApi(it)
|
|
||||||
log.info(
|
|
||||||
"JSONA Using {}", it.javaClass.name
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-21
@@ -16,19 +16,19 @@
|
|||||||
* ProjectName mingli-utils
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile JacksonJsonAutoConfiguration.kt
|
* CurrentFile JacksonJsonAutoConfiguration.kt
|
||||||
* LastUpdate 2026-10-28 23:30:03
|
* LastUpdate 2026-11-09 14:19:05
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.mingliqiye.utils.springboot.autoconfigure
|
package com.mingliqiye.utils.springboot.autoconfigure
|
||||||
|
|
||||||
import com.mingliqiye.utils.json.converters.DateTimeJsonConverter
|
|
||||||
import com.mingliqiye.utils.json.converters.UUIDJsonConverter
|
|
||||||
import com.mingliqiye.utils.json.converters.base.getJacksonModule
|
import com.mingliqiye.utils.json.converters.base.getJacksonModule
|
||||||
import com.mingliqiye.utils.logger.MingLiLoggerFactory
|
import com.mingliqiye.utils.logger.MingLiLoggerFactory
|
||||||
|
import com.mingliqiye.utils.springboot.autoconfigure.builder.JacksonBuilder
|
||||||
|
import com.mingliqiye.utils.springboot.autoconfigure.builder.JacksonJsonBuilderImpl
|
||||||
|
import org.springframework.beans.factory.ObjectProvider
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
|
||||||
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer
|
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer
|
||||||
import org.springframework.context.annotation.Bean
|
import org.springframework.context.annotation.Bean
|
||||||
|
|
||||||
@@ -67,26 +67,23 @@ open class JacksonJsonAutoConfiguration {
|
|||||||
private val log = MingLiLoggerFactory.getLogger<JacksonJsonAutoConfiguration>()
|
private val log = MingLiLoggerFactory.getLogger<JacksonJsonAutoConfiguration>()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("DateTimeJsonConverterJackson2ObjectMapperBuilderCustomizer")
|
@Bean("mingliUtilsJacksonObjectMapperBuilderCustomizer")
|
||||||
@ConditionalOnMissingBean(name = ["DateTimeJsonConverterJackson2ObjectMapperBuilderCustomizer"])
|
fun jackson2ObjectMapperBuilderCustomizer(builders: ObjectProvider<JacksonBuilder>): Jackson2ObjectMapperBuilderCustomizer {
|
||||||
fun getDateTimeJsonConverterJackson2ObjectMapperBuilderCustomizer() = Jackson2ObjectMapperBuilderCustomizer {
|
val builderList = builders.orderedStream().toList()
|
||||||
log.info(
|
var jacksonJsonBuilderImpl = JacksonJsonBuilderImpl()
|
||||||
"MingliUtils Jackson2 DateTime Serializers created"
|
builderList.forEach {
|
||||||
)
|
jacksonJsonBuilderImpl = it.customize(jacksonJsonBuilderImpl) as JacksonJsonBuilderImpl
|
||||||
it.modulesToInstall { modules ->
|
|
||||||
modules.add(DateTimeJsonConverter.getJsonConverter().getJacksonModule())
|
|
||||||
}
|
}
|
||||||
|
return Jackson2ObjectMapperBuilderCustomizer { builder ->
|
||||||
|
builder.modulesToInstall(
|
||||||
|
*jacksonJsonBuilderImpl.getData().map { converter ->
|
||||||
|
converter.getJacksonModule().also { module ->
|
||||||
|
log.info("Jackson Module Install ${module.moduleName}")
|
||||||
|
}
|
||||||
|
}.toTypedArray()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("UUIDJsonConverterJackson2ObjectMapperBuilderCustomizer")
|
|
||||||
@ConditionalOnMissingBean(name = ["UUIDJsonConverterJackson2ObjectMapperBuilderCustomizer"])
|
|
||||||
fun getUUIDJsonConverterJackson2ObjectMapperBuilderCustomizer() = Jackson2ObjectMapperBuilderCustomizer {
|
|
||||||
log.info(
|
|
||||||
"MingliUtils Jackson2 UUID Serializers created"
|
|
||||||
)
|
|
||||||
it.modulesToInstall { modules ->
|
|
||||||
modules.add(UUIDJsonConverter.getJsonConverter().getJacksonModule())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+46
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2026 mingliqiye
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* ProjectName mingli-utils
|
||||||
|
* ModuleName mingli-utils.main
|
||||||
|
* CurrentFile JsonAutoConfiguration.kt
|
||||||
|
* LastUpdate 2026-11-09 14:44:55
|
||||||
|
* UpdateUser MingLiPro
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.mingliqiye.utils.springboot.autoconfigure
|
||||||
|
|
||||||
|
import com.mingliqiye.utils.json.converters.DateTimeJsonConverter
|
||||||
|
import com.mingliqiye.utils.json.converters.NetworkEndpointJsonConverter
|
||||||
|
import com.mingliqiye.utils.json.converters.UUIDJsonConverter
|
||||||
|
import com.mingliqiye.utils.springboot.autoconfigure.builder.JacksonBuilder
|
||||||
|
import org.springframework.boot.autoconfigure.AutoConfiguration
|
||||||
|
import org.springframework.context.annotation.Bean
|
||||||
|
|
||||||
|
@AutoConfiguration
|
||||||
|
open class JsonAutoConfiguration {
|
||||||
|
|
||||||
|
@Bean("mingliUtilsJacksonBuilder")
|
||||||
|
fun jacksonBuilder(): JacksonBuilder = JacksonBuilder {
|
||||||
|
it.apply {
|
||||||
|
addJsonConverters(
|
||||||
|
UUIDJsonConverter.getJsonConverter(),
|
||||||
|
DateTimeJsonConverter.getJsonConverter(),
|
||||||
|
NetworkEndpointJsonConverter.getJsonConverter(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+54
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2026 mingliqiye
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* ProjectName mingli-utils
|
||||||
|
* ModuleName mingli-utils.main
|
||||||
|
* CurrentFile JacksonBuilder.kt
|
||||||
|
* LastUpdate 2026-11-09 14:39:28
|
||||||
|
* UpdateUser MingLiPro
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.mingliqiye.utils.springboot.autoconfigure.builder
|
||||||
|
|
||||||
|
import com.mingliqiye.utils.json.converters.base.JsonConverter
|
||||||
|
|
||||||
|
sealed class JacksonJsonBuilder {
|
||||||
|
abstract fun addJsonConverter(jsonConverter: JsonConverter<*, *>): JacksonJsonBuilder
|
||||||
|
abstract fun addJsonConverters(vararg jsonConverters: JsonConverter<*, *>): JacksonJsonBuilder
|
||||||
|
}
|
||||||
|
|
||||||
|
open class JacksonJsonBuilderImpl : JacksonJsonBuilder() {
|
||||||
|
override fun addJsonConverter(jsonConverter: JsonConverter<*, *>): JacksonJsonBuilderImpl {
|
||||||
|
data.add(jsonConverter)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun addJsonConverters(vararg jsonConverters: JsonConverter<*, *>): JacksonJsonBuilder {
|
||||||
|
data.addAll(jsonConverters)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
private val data = mutableListOf<JsonConverter<*, *>>()
|
||||||
|
|
||||||
|
fun getData(): List<JsonConverter<*, *>> {
|
||||||
|
return data.toList()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
fun interface JacksonBuilder {
|
||||||
|
fun customize(builder: JacksonJsonBuilder): JacksonJsonBuilder
|
||||||
|
}
|
||||||
+2
-2
@@ -13,10 +13,10 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
* ProjectName FastBaseMapper.kt
|
* ProjectName mingli-utils
|
||||||
* ModuleName mingli-utils.main
|
* ModuleName mingli-utils.main
|
||||||
* CurrentFile OkhttpBuilder.kt
|
* CurrentFile OkhttpBuilder.kt
|
||||||
* LastUpdate 2026-10-26 23:22:18
|
* LastUpdate 2026-11-09 13:32:25
|
||||||
* UpdateUser MingLiPro
|
* UpdateUser MingLiPro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -13,16 +13,18 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
# ProjectName FastBaseMapper.kt
|
# ProjectName mingli-utils
|
||||||
# ModuleName mingli-utils.main
|
# ModuleName mingli-utils.main
|
||||||
# CurrentFile org.springframework.boot.autoconfigure.AutoConfiguration.imports
|
# CurrentFile org.springframework.boot.autoconfigure.AutoConfiguration.imports
|
||||||
# LastUpdate 2026-10-26 23:22:18
|
# LastUpdate 2026-11-09 14:45:58
|
||||||
# UpdateUser MingLiPro
|
# UpdateUser MingLiPro
|
||||||
#
|
#
|
||||||
|
|
||||||
com.mingliqiye.utils.springboot.autoconfigure.AutoConfiguration
|
com.mingliqiye.utils.springboot.autoconfigure.AutoConfiguration
|
||||||
|
com.mingliqiye.utils.springboot.autoconfigure.JsonAutoConfiguration
|
||||||
com.mingliqiye.utils.springboot.autoconfigure.JacksonJsonAutoConfiguration
|
com.mingliqiye.utils.springboot.autoconfigure.JacksonJsonAutoConfiguration
|
||||||
com.mingliqiye.utils.springboot.autoconfigure.JacksonJsonApiAutoConfiguration
|
com.mingliqiye.utils.springboot.autoconfigure.JacksonJsonApiAutoConfiguration
|
||||||
com.mingliqiye.utils.springboot.autoconfigure.Jackson3AutoConfiguration
|
com.mingliqiye.utils.springboot.autoconfigure.Jackson3AutoConfiguration
|
||||||
com.mingliqiye.utils.springboot.autoconfigure.Jackson3JsonApiAutoConfiguration
|
com.mingliqiye.utils.springboot.autoconfigure.Jackson3JsonApiAutoConfiguration
|
||||||
|
com.mingliqiye.utils.springboot.autoconfigure.JSONAAutoConfiguration
|
||||||
com.mingliqiye.utils.springboot.autoconfigure.Okhttp3AutoConfiguration
|
com.mingliqiye.utils.springboot.autoconfigure.Okhttp3AutoConfiguration
|
||||||
|
|||||||
Reference in New Issue
Block a user