Compare commits
4
Commits
535c03d14a
...
5.4.4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
16da482de7
|
||
|
|
aa83f575b1
|
||
|
|
510ff69e2c
|
||
|
|
184db461d7
|
+40
-15
@@ -16,12 +16,37 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils
|
||||
* CurrentFile build.gradle.kts
|
||||
* LastUpdate 2026-10-28 21:50:32
|
||||
* LastUpdate 2026-11-17 10:19:02
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
import kotlin.math.sign
|
||||
|
||||
/*
|
||||
* 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
|
||||
* CurrentFile build.gradle.kts
|
||||
* LastUpdate 2026-11-17 10:18:28
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
|
||||
|
||||
plugins {
|
||||
idea
|
||||
@@ -61,7 +86,8 @@ kotlin {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
maven {
|
||||
url = uri("https://maven.mingliqiye.com/")
|
||||
name = "mingliqiye-public"
|
||||
url = uri("https://repository.mingliqiye.com/repository/maven-public/")
|
||||
}
|
||||
mavenCentral()
|
||||
}
|
||||
@@ -160,32 +186,31 @@ tasks.withType<org.gradle.jvm.tasks.Jar> {
|
||||
}
|
||||
val isJdk8Build = project.findProperty("buildForJdk8") == "true"
|
||||
|
||||
|
||||
dokka {
|
||||
pluginsConfiguration.html {
|
||||
customAssets.from("logo.png")
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register<Jar>("javaDocJar") {
|
||||
group = "build"
|
||||
archiveClassifier.set("javadoc-dec")
|
||||
dependsOn("dokkaGeneratePublicationJavadoc")
|
||||
archiveClassifier.set("javadoc")
|
||||
dependsOn("dokkaGenerateJavadoc")
|
||||
from(buildDir.resolve("dokka/javadoc"))
|
||||
}
|
||||
|
||||
tasks.register<Jar>("kotlinDocJar") {
|
||||
group = "build"
|
||||
archiveClassifier.set("javadoc")
|
||||
archiveClassifier.set("kotlindoc")
|
||||
dependsOn("dokkaGeneratePublicationHtml")
|
||||
from(buildDir.resolve("dokka/html"))
|
||||
}
|
||||
publishing {
|
||||
repositories {
|
||||
maven {
|
||||
name = "mingliqiye"
|
||||
url = uri("https://repository.mingliqiye.com/repository/maven")
|
||||
credentials {
|
||||
username = System.getenv("mingliqiye.username")
|
||||
password = System.getenv("mingliqiye.password")
|
||||
}
|
||||
}
|
||||
}
|
||||
publications {
|
||||
create<MavenPublication>("mavenJava") {
|
||||
from(components["java"])
|
||||
artifact(tasks.named("javaDocJar"))
|
||||
artifact(tasks.named("kotlinDocJar"))
|
||||
artifactId = ARTIFACTID
|
||||
pom {
|
||||
|
||||
+2
-2
@@ -16,10 +16,10 @@
|
||||
# ProjectName mingli-utils
|
||||
# ModuleName mingli-utils
|
||||
# CurrentFile gradle.properties
|
||||
# LastUpdate 2026-11-07 13:47:56
|
||||
# LastUpdate 2026-11-17 09:07:20
|
||||
# UpdateUser MingLiPro
|
||||
#
|
||||
JDKVERSIONS=17
|
||||
GROUPSID=com.mingliqiye.utils
|
||||
ARTIFACTID=mingli-utils
|
||||
VERSIONS=5.4.2
|
||||
VERSIONS=5.4.4
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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 Base64NoPaddingCodec.kt
|
||||
* LastUpdate 2026-11-16 14:24:59
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
package com.mingliqiye.utils.base
|
||||
|
||||
import java.util.*
|
||||
|
||||
internal class Base64NoPaddingCodec : BaseCodec {
|
||||
|
||||
/*
|
||||
* Base64编码器实例
|
||||
* 用于执行字节数组到Base64字符串的编码操作
|
||||
*/
|
||||
val encoder: Base64.Encoder = Base64.getUrlEncoder().withoutPadding()
|
||||
|
||||
/*
|
||||
* Base64解码器实例
|
||||
* 用于执行Base64字符串到字节数组的解码操作
|
||||
*/
|
||||
val decoder: Base64.Decoder = Base64.getUrlDecoder()
|
||||
|
||||
/*
|
||||
* 将字节数组编码为Base64字符串
|
||||
*
|
||||
* @param bytes 待编码的字节数组
|
||||
* @return 编码后的Base64字符串
|
||||
*/
|
||||
override fun encode(bytes: ByteArray): String {
|
||||
return encoder.encodeToString(bytes)
|
||||
}
|
||||
|
||||
/*
|
||||
* 将Base64字符串解码为字节数组
|
||||
*
|
||||
* @param string 待解码的Base64字符串
|
||||
* @return 解码后的字节数组
|
||||
*/
|
||||
override fun decode(string: String): ByteArray {
|
||||
return decoder.decode(string)
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile Base64UrlCodec.kt
|
||||
* LastUpdate 2026-03-12 10:34:36
|
||||
* LastUpdate 2026-11-16 14:24:59
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
|
||||
@@ -16,23 +16,36 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile BaseType.kt
|
||||
* LastUpdate 2026-03-12 10:08:42
|
||||
* LastUpdate 2026-11-16 14:21:51
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
package com.mingliqiye.utils.base
|
||||
|
||||
enum class BaseType(val baseCodec: BaseCodec) : BaseCodec {
|
||||
import com.mingliqiye.utils.base.code.BASE10 as CODE_BASE10
|
||||
import com.mingliqiye.utils.base.code.BASE16 as CODE_BASE16
|
||||
import com.mingliqiye.utils.base.code.BASE2 as CODE_BASE2
|
||||
import com.mingliqiye.utils.base.code.BASE256 as CODE_BASE256
|
||||
import com.mingliqiye.utils.base.code.BASE64 as CODE_BASE64
|
||||
import com.mingliqiye.utils.base.code.BASE64_NO_PADDING as CODE_BASE64_NO_PADDING
|
||||
import com.mingliqiye.utils.base.code.BASE64_URL as CODE_BASE64_URL
|
||||
import com.mingliqiye.utils.base.code.BASE91 as CODE_BASE91
|
||||
|
||||
BASE2(com.mingliqiye.utils.base.code.BASE2),
|
||||
BASE10(com.mingliqiye.utils.base.code.BASE10),
|
||||
BASE16(com.mingliqiye.utils.base.code.BASE16),
|
||||
BASE64(com.mingliqiye.utils.base.code.BASE64),
|
||||
BASE64URL(com.mingliqiye.utils.base.code.BASE64URL),
|
||||
BASE91(com.mingliqiye.utils.base.code.BASE91),
|
||||
BASE256(com.mingliqiye.utils.base.code.BASE256);
|
||||
enum class BaseType(private val baseCodec: () -> BaseCodec) : BaseCodec {
|
||||
|
||||
override fun encode(bytes: ByteArray) = baseCodec.encode(bytes)
|
||||
override fun decode(string: String) = baseCodec.decode(string)
|
||||
BASE2(::CODE_BASE2),
|
||||
BASE10(::CODE_BASE10),
|
||||
BASE16(::CODE_BASE16),
|
||||
BASE64(::CODE_BASE64),
|
||||
BASE64_URL(::CODE_BASE64_URL),
|
||||
BASE64_NO_PADDING(::CODE_BASE64_NO_PADDING),
|
||||
BASE91(::CODE_BASE91),
|
||||
BASE256(::CODE_BASE256);
|
||||
|
||||
val codec
|
||||
get() = baseCodec()
|
||||
|
||||
override fun encode(bytes: ByteArray) = codec.encode(bytes)
|
||||
override fun decode(string: String) = codec.decode(string)
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile BaseCodes.kt
|
||||
* LastUpdate 2026-03-12 10:03:32
|
||||
* LastUpdate 2026-11-16 14:10:57
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
@@ -63,10 +63,16 @@ val BASE64: BaseCodec by lazy {
|
||||
}
|
||||
|
||||
@get:JvmName("base64Url")
|
||||
val BASE64URL: BaseCodec by lazy {
|
||||
val BASE64_URL: BaseCodec by lazy {
|
||||
Base64UrlCodec()
|
||||
}
|
||||
|
||||
@get:JvmName("base64NoPadding")
|
||||
val BASE64_NO_PADDING: BaseCodec by lazy {
|
||||
Base64NoPaddingCodec()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 提供Base91编码器的懒加载实例。
|
||||
* 该编码器用于将数据编码为Base91格式,具有较高的压缩效率。
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile ByteFlags.kt
|
||||
* LastUpdate 2026-06-21 10:40:58
|
||||
* LastUpdate 2026-11-16 21:35:04
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
@@ -64,7 +64,7 @@ data class ByteFlags(
|
||||
*
|
||||
* @param byte 要解析的字节
|
||||
*/
|
||||
fun fromByte(byte: Byte) {
|
||||
fun fromByte(byte: Byte): ByteFlags {
|
||||
val value = byte.toInt() and 0xFF
|
||||
b0 = (value and 0x01) != 0
|
||||
b1 = (value and 0x02) != 0
|
||||
@@ -74,6 +74,7 @@ data class ByteFlags(
|
||||
b5 = (value and 0x20) != 0
|
||||
b6 = (value and 0x40) != 0
|
||||
b7 = (value and 0x80) != 0
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,7 +123,7 @@ data class ByteFlags(
|
||||
* @param value 要设置的布尔值
|
||||
* @throws IndexOutOfBoundsException 如果索引不在 0~7 范围内
|
||||
*/
|
||||
operator fun set(index: Int, value: Boolean) {
|
||||
operator fun set(index: Int, value: Boolean): ByteFlags {
|
||||
when (index) {
|
||||
0 -> b0 = value
|
||||
1 -> b1 = value
|
||||
@@ -134,12 +135,13 @@ data class ByteFlags(
|
||||
7 -> b7 = value
|
||||
else -> throw IndexOutOfBoundsException("索引必须在0-7之间")
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* 将所有 8 个位设置为 `true`。
|
||||
*/
|
||||
fun setAll() {
|
||||
fun setAll(): ByteFlags {
|
||||
b0 = true
|
||||
b1 = true
|
||||
b2 = true
|
||||
@@ -148,12 +150,14 @@ data class ByteFlags(
|
||||
b5 = true
|
||||
b6 = true
|
||||
b7 = true
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* 将所有 8 个位设置为 `false`。
|
||||
*/
|
||||
fun clearAll() {
|
||||
fun clearAll(): ByteFlags {
|
||||
b0 = false
|
||||
b1 = false
|
||||
b2 = false
|
||||
@@ -162,12 +166,14 @@ data class ByteFlags(
|
||||
b5 = false
|
||||
b6 = false
|
||||
b7 = false
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* 对所有位执行逻辑取反(true ↔ false)。
|
||||
*/
|
||||
fun toggleAll() {
|
||||
fun toggleAll(): ByteFlags {
|
||||
b0 = !b0
|
||||
b1 = !b1
|
||||
b2 = !b2
|
||||
@@ -176,6 +182,8 @@ data class ByteFlags(
|
||||
b5 = !b5
|
||||
b6 = !b6
|
||||
b7 = !b7
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,8 +192,9 @@ data class ByteFlags(
|
||||
* @param index 要切换的位索引(0~7)
|
||||
* @throws IndexOutOfBoundsException 如果索引无效
|
||||
*/
|
||||
fun toggle(index: Int) {
|
||||
fun toggle(index: Int): ByteFlags {
|
||||
this[index] = !this[index]
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -304,7 +313,7 @@ data class ByteFlags(
|
||||
* @param array 布尔数组(长度至少为 8)
|
||||
* @throws IllegalArgumentException 如果数组长度不足 8
|
||||
*/
|
||||
fun fromBooleanArray(array: BooleanArray) {
|
||||
fun fromBooleanArray(array: BooleanArray): ByteFlags {
|
||||
require(array.size >= 8) { "数组长度至少为8" }
|
||||
b0 = array[0]
|
||||
b1 = array[1]
|
||||
@@ -314,6 +323,7 @@ data class ByteFlags(
|
||||
b5 = array[5]
|
||||
b6 = array[6]
|
||||
b7 = array[7]
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -434,7 +444,6 @@ data class ByteFlags(
|
||||
fun fromBinaryString(binary: String): ByteFlags {
|
||||
require(binary.length == 8) { "二进制字符串长度必须为8" }
|
||||
require(binary.all { it == '0' || it == '1' }) { "二进制字符串只能包含0和1" }
|
||||
|
||||
return ByteFlags(
|
||||
binary[7] == '1', // b0 是最低位(对应字符串最后一位)
|
||||
binary[6] == '1',
|
||||
@@ -447,6 +456,10 @@ data class ByteFlags(
|
||||
)
|
||||
}
|
||||
|
||||
fun fromBooleanArray(booleanArray: BooleanArray): ByteFlags {
|
||||
return ByteFlags().fromBooleanArray(booleanArray)
|
||||
}
|
||||
|
||||
/**
|
||||
* 从整数创建 [ByteFlags] 实例(仅使用低 8 位)。
|
||||
*
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile OkHttpUtils.kt
|
||||
* LastUpdate 2026-11-07 13:44:21
|
||||
* LastUpdate 2026-11-09 19:18:03
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
@file:JvmName("OkHttpUtils")
|
||||
@@ -298,3 +298,8 @@ enum class Method {
|
||||
/** QUERY 方法(HTTP 扩展方法,需服务端支持)。 */
|
||||
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
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile DateTimeJsonConverter.kt
|
||||
* LastUpdate 2026-02-07 22:13:41
|
||||
* LastUpdate 2026-11-09 14:35:06
|
||||
* 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()
|
||||
}
|
||||
@@ -16,7 +16,7 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile MingLiLogger.kt
|
||||
* LastUpdate 2026-02-06 08:27:44
|
||||
* LastUpdate 2026-11-16 11:35:40
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
@@ -24,6 +24,7 @@ package com.mingliqiye.utils.logger
|
||||
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.Marker
|
||||
import org.slf4j.helpers.MessageFormatter
|
||||
|
||||
class MingLiLogger(private val name: String) : Logger {
|
||||
override fun getName(): String {
|
||||
@@ -40,14 +41,14 @@ class MingLiLogger(private val name: String) : Logger {
|
||||
|
||||
override fun trace(format: String?, arg: Any?) {
|
||||
format?.let {
|
||||
val message = format1(it, arg)
|
||||
val message = format(it, arg)
|
||||
toPrintln(message, MingLiLoggerLevel.TRACE)
|
||||
}
|
||||
}
|
||||
|
||||
override fun trace(format: String?, arg1: Any?, arg2: Any?) {
|
||||
format?.let {
|
||||
val message = format2(it, arg1, arg2)
|
||||
val message = format(it, arg1, arg2)
|
||||
toPrintln(message, MingLiLoggerLevel.TRACE)
|
||||
}
|
||||
}
|
||||
@@ -100,14 +101,14 @@ class MingLiLogger(private val name: String) : Logger {
|
||||
|
||||
override fun debug(format: String?, arg: Any?) {
|
||||
format?.let {
|
||||
val message = format1(it, arg)
|
||||
val message = format(it, arg)
|
||||
toPrintln(message, MingLiLoggerLevel.DEBUG)
|
||||
}
|
||||
}
|
||||
|
||||
override fun debug(format: String?, arg1: Any?, arg2: Any?) {
|
||||
format?.let {
|
||||
val message = format2(it, arg1, arg2)
|
||||
val message = format(it, arg1, arg2)
|
||||
toPrintln(message, MingLiLoggerLevel.DEBUG)
|
||||
}
|
||||
}
|
||||
@@ -160,14 +161,14 @@ class MingLiLogger(private val name: String) : Logger {
|
||||
|
||||
override fun info(format: String?, arg: Any?) {
|
||||
format?.let {
|
||||
val message = format1(it, arg)
|
||||
val message = format(it, arg)
|
||||
toPrintln(message, MingLiLoggerLevel.INFO)
|
||||
}
|
||||
}
|
||||
|
||||
override fun info(format: String?, arg1: Any?, arg2: Any?) {
|
||||
format?.let {
|
||||
val message = format2(it, arg1, arg2)
|
||||
val message = format(it, arg1, arg2)
|
||||
toPrintln(message, MingLiLoggerLevel.INFO)
|
||||
}
|
||||
}
|
||||
@@ -220,7 +221,7 @@ class MingLiLogger(private val name: String) : Logger {
|
||||
|
||||
override fun warn(format: String?, arg: Any?) {
|
||||
format?.let {
|
||||
val message = format1(it, arg)
|
||||
val message = format(it, arg)
|
||||
toPrintln(message, MingLiLoggerLevel.WARN)
|
||||
}
|
||||
}
|
||||
@@ -234,7 +235,7 @@ class MingLiLogger(private val name: String) : Logger {
|
||||
|
||||
override fun warn(format: String?, arg1: Any?, arg2: Any?) {
|
||||
format?.let {
|
||||
val message = format2(it, arg1, arg2)
|
||||
val message = format(it, arg1, arg2)
|
||||
toPrintln(message, MingLiLoggerLevel.WARN)
|
||||
}
|
||||
}
|
||||
@@ -280,14 +281,14 @@ class MingLiLogger(private val name: String) : Logger {
|
||||
|
||||
override fun error(format: String?, arg: Any?) {
|
||||
format?.let {
|
||||
val message = format1(it, arg)
|
||||
val message = format(it, arg)
|
||||
toPrintln(message, MingLiLoggerLevel.ERROR)
|
||||
}
|
||||
}
|
||||
|
||||
override fun error(format: String?, arg1: Any?, arg2: Any?) {
|
||||
format?.let {
|
||||
val message = format2(it, arg1, arg2)
|
||||
val message = format(it, arg1, arg2)
|
||||
toPrintln(message, MingLiLoggerLevel.ERROR)
|
||||
}
|
||||
}
|
||||
@@ -343,24 +344,14 @@ class MingLiLogger(private val name: String) : Logger {
|
||||
System.out.write(string.toByteArray())
|
||||
}
|
||||
|
||||
private fun format1(format: String, arg: Any?): String {
|
||||
return if (format.contains("{}")) {
|
||||
format.replaceFirst("{}", arg?.toString() ?: "null")
|
||||
} else {
|
||||
"$format $arg"
|
||||
}
|
||||
}
|
||||
|
||||
private fun format2(format: String, arg1: Any?, arg2: Any?): String {
|
||||
return format.replaceFirst("{}", arg1?.toString() ?: "null")
|
||||
.replaceFirst("{}", arg2?.toString() ?: "null")
|
||||
private fun format(format: String, vararg args: Any?): String {
|
||||
return formatArray(format, args)
|
||||
}
|
||||
|
||||
private fun formatArray(format: String, arguments: Array<out Any?>): String {
|
||||
var result = format
|
||||
for (arg in arguments) {
|
||||
result = result.replaceFirst("{}", arg?.toString() ?: "null")
|
||||
}
|
||||
return result
|
||||
return MessageFormatter.arrayFormat(
|
||||
format,
|
||||
arguments
|
||||
).message
|
||||
}
|
||||
}
|
||||
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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-16 11:28:52
|
||||
* 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
|
||||
)
|
||||
}
|
||||
}
|
||||
+23
-32
@@ -13,19 +13,20 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ProjectName FastBaseMapper.kt
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile Jackson3AutoConfiguration.kt
|
||||
* LastUpdate 2026-10-26 23:22:18
|
||||
* LastUpdate 2026-11-17 10:16:38
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
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.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.condition.ConditionalOnClass
|
||||
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"])
|
||||
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")
|
||||
@ConditionalOnMissingBean(name = ["UUIDJsonConverterJsonMapperCustomizer"])
|
||||
open fun getUUIDJsonConverterJsonMapperCustomizer(): JsonMapperBuilderCustomizer {
|
||||
return JsonMapperBuilderCustomizer { builder ->
|
||||
builder.addModule(UUIDJsonConverter.getJsonConverter().getJackson3Module())
|
||||
}.also {
|
||||
logger.info("MingliUtils Jackson3 UUID Serializers created")
|
||||
@Bean("jackson3MapperBuilderCustomizer")
|
||||
@ConditionalOnMissingBean(name = ["jackson3MapperBuilderCustomizer"])
|
||||
fun jsonMapperBuilderCustomizer(builders: ObjectProvider<JacksonBuilder>): JsonMapperBuilderCustomizer {
|
||||
val builderList = builders.orderedStream().toList()
|
||||
var jacksonJsonBuilderImpl = JacksonJsonBuilderImpl()
|
||||
log.info("scan ${builderList.size} JacksonBuilders")
|
||||
builderList.forEach {
|
||||
jacksonJsonBuilderImpl = it.customize(jacksonJsonBuilderImpl) as JacksonJsonBuilderImpl
|
||||
}
|
||||
return JsonMapperBuilderCustomizer {
|
||||
it.addModules(
|
||||
*jacksonJsonBuilderImpl.getData().map { converter ->
|
||||
converter.getJackson3Module().also { module ->
|
||||
log.debug("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")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+5
-36
@@ -13,10 +13,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ProjectName FastBaseMapper.kt
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile Jackson3JsonApiAutoConfiguration.kt
|
||||
* LastUpdate 2026-10-26 23:22:18
|
||||
* LastUpdate 2026-11-09 13:45:29
|
||||
* 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.Jackson3JsonApi
|
||||
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.condition.ConditionalOnClass
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Primary
|
||||
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"])
|
||||
@AutoConfigureAfter(name = ["com.mingliqiye.utils.springboot.autoconfigure.Jackson3AutoConfiguration"])
|
||||
open class Jackson3JsonApiAutoConfiguration {
|
||||
|
||||
companion object {
|
||||
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
|
||||
@Bean("jackson3JsonApi")
|
||||
@Primary
|
||||
@ConditionalOnMissingBean(JsonApi::class)
|
||||
open fun jsonApi(jsonMapper: JsonMapper): JsonApi {
|
||||
return Jackson3JsonApi(
|
||||
get = { jsonMapper },
|
||||
set = { throw JsonException("JSON API set method is not allowed.") })
|
||||
.also {
|
||||
logger.info("JsonApi Bean Auto Configuration Success")
|
||||
try {
|
||||
JSONA.getJsonApi()
|
||||
} catch (_: NullPointerException) {
|
||||
JSONA.setJsonApi(it)
|
||||
logger.info(
|
||||
"JSONA Using {}", it.javaClass.name
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-33
@@ -13,26 +13,22 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ProjectName FastBaseMapper.kt
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile JacksonJsonApiAutoConfiguration.kt
|
||||
* LastUpdate 2026-10-26 23:22:18
|
||||
* LastUpdate 2026-11-09 13:45:41
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
package com.mingliqiye.utils.springboot.autoconfigure
|
||||
|
||||
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.base.JsonApi
|
||||
import com.mingliqiye.utils.logger.MingLiLoggerFactory
|
||||
import org.slf4j.Logger
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Primary
|
||||
|
||||
/*
|
||||
* 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"])
|
||||
@AutoConfigureAfter(name = ["com.mingliqiye.utils.springboot.autoconfigure.JacksonJsonAutoConfiguration"])
|
||||
open class JacksonJsonApiAutoConfiguration {
|
||||
|
||||
|
||||
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
|
||||
@Bean("jacksonJsonApi")
|
||||
@ConditionalOnMissingBean(JsonApi::class)
|
||||
open fun jsonApi(objectMapper: ObjectMapper): JsonApi {
|
||||
return JacksonJsonApi(objectMapper).also {
|
||||
log.info("JsonApi Bean Auto Configuration Success")
|
||||
try {
|
||||
JSONA.getJsonApi()
|
||||
} catch (_: NullPointerException) {
|
||||
JSONA.setJsonApi(it)
|
||||
log.info(
|
||||
"JSONA Using {}", it.javaClass.name
|
||||
)
|
||||
}
|
||||
}
|
||||
return JacksonJsonApi(objectMapper)
|
||||
}
|
||||
}
|
||||
|
||||
+19
-20
@@ -16,16 +16,17 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile JacksonJsonAutoConfiguration.kt
|
||||
* LastUpdate 2026-10-28 23:30:03
|
||||
* LastUpdate 2026-11-16 23:32:09
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
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.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.condition.ConditionalOnClass
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
||||
@@ -67,26 +68,24 @@ open class JacksonJsonAutoConfiguration {
|
||||
private val log = MingLiLoggerFactory.getLogger<JacksonJsonAutoConfiguration>()
|
||||
}
|
||||
|
||||
@Bean("DateTimeJsonConverterJackson2ObjectMapperBuilderCustomizer")
|
||||
@ConditionalOnMissingBean(name = ["DateTimeJsonConverterJackson2ObjectMapperBuilderCustomizer"])
|
||||
fun getDateTimeJsonConverterJackson2ObjectMapperBuilderCustomizer() = Jackson2ObjectMapperBuilderCustomizer {
|
||||
log.info(
|
||||
"MingliUtils Jackson2 DateTime Serializers created"
|
||||
)
|
||||
it.modulesToInstall { modules ->
|
||||
modules.add(DateTimeJsonConverter.getJsonConverter().getJacksonModule())
|
||||
@Bean("jacksonMapperBuilderCustomizer")
|
||||
@ConditionalOnMissingBean(name = ["jacksonMapperBuilderCustomizer"])
|
||||
fun jackson2ObjectMapperBuilderCustomizer(builders: ObjectProvider<JacksonBuilder>): Jackson2ObjectMapperBuilderCustomizer {
|
||||
val builderList = builders.orderedStream().toList()
|
||||
var jacksonJsonBuilderImpl = JacksonJsonBuilderImpl()
|
||||
builderList.forEach {
|
||||
jacksonJsonBuilderImpl = it.customize(jacksonJsonBuilderImpl) as JacksonJsonBuilderImpl
|
||||
}
|
||||
return Jackson2ObjectMapperBuilderCustomizer { builder ->
|
||||
builder.modulesToInstall(
|
||||
*jacksonJsonBuilderImpl.getData().map { converter ->
|
||||
converter.getJacksonModule().also { module ->
|
||||
log.debug("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(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+3
-3
@@ -13,10 +13,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ProjectName FastBaseMapper.kt
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile Okhttp3AutoConfiguration.kt
|
||||
* LastUpdate 2026-10-26 23:22:18
|
||||
* LastUpdate 2026-11-16 11:29:35
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
@@ -98,7 +98,7 @@ open class Okhttp3AutoConfiguration {
|
||||
b.build()
|
||||
}.also {
|
||||
okhttp = it
|
||||
log.info("load $connt OkhttpBuilder initialized OkHttpClient successfully")
|
||||
log.info("load {} OkhttpBuilder initialized OkHttpClient successfully", connt)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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-16 11:36:46
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
package com.mingliqiye.utils.springboot.autoconfigure.builder
|
||||
|
||||
@FunctionalInterface
|
||||
fun interface JacksonBuilder {
|
||||
fun customize(builder: JacksonJsonBuilder): JacksonJsonBuilder
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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 JacksonJsonBuilder.kt
|
||||
* LastUpdate 2026-11-16 11:36:46
|
||||
* 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
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 JacksonJsonBuilderImpl.kt
|
||||
* LastUpdate 2026-11-16 11:36:46
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
package com.mingliqiye.utils.springboot.autoconfigure.builder
|
||||
|
||||
import com.mingliqiye.utils.json.converters.base.JsonConverter
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
}
|
||||
+2
-2
@@ -13,10 +13,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ProjectName FastBaseMapper.kt
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile OkhttpBuilder.kt
|
||||
* LastUpdate 2026-10-26 23:22:18
|
||||
* LastUpdate 2026-11-09 13:32:25
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile DateTime.kt
|
||||
* LastUpdate 2026-03-14 16:12:08
|
||||
* LastUpdate 2026-11-17 10:16:38
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
@@ -543,4 +543,9 @@ class DateTime private constructor(
|
||||
(it.epochSecond * 1000L) + (it.nano / 1_000_000L)
|
||||
}
|
||||
}
|
||||
|
||||
val epochSecond: Long
|
||||
get() {
|
||||
return toInstant().epochSecond
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile UUID.kt
|
||||
* LastUpdate 2026-06-21 10:40:58
|
||||
* LastUpdate 2026-11-16 14:29:35
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
@@ -422,7 +422,7 @@ class UUID : Serializable {
|
||||
}
|
||||
|
||||
fun of(str: String, base: BaseType): UUID {
|
||||
return UUID(base.baseCodec.decode(str))
|
||||
return UUID(base.codec.decode(str))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -552,7 +552,7 @@ class UUID : Serializable {
|
||||
}
|
||||
|
||||
fun getString(baseType: BaseType): String {
|
||||
return getString(baseType.baseCodec)
|
||||
return getString(baseType.codec)
|
||||
}
|
||||
|
||||
fun getString(baseCodec: BaseCodec): String {
|
||||
|
||||
+4
-2
@@ -13,16 +13,18 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# ProjectName FastBaseMapper.kt
|
||||
# ProjectName mingli-utils
|
||||
# ModuleName mingli-utils.main
|
||||
# CurrentFile org.springframework.boot.autoconfigure.AutoConfiguration.imports
|
||||
# LastUpdate 2026-10-26 23:22:18
|
||||
# LastUpdate 2026-11-09 14:45:58
|
||||
# UpdateUser MingLiPro
|
||||
#
|
||||
|
||||
com.mingliqiye.utils.springboot.autoconfigure.AutoConfiguration
|
||||
com.mingliqiye.utils.springboot.autoconfigure.JsonAutoConfiguration
|
||||
com.mingliqiye.utils.springboot.autoconfigure.JacksonJsonAutoConfiguration
|
||||
com.mingliqiye.utils.springboot.autoconfigure.JacksonJsonApiAutoConfiguration
|
||||
com.mingliqiye.utils.springboot.autoconfigure.Jackson3AutoConfiguration
|
||||
com.mingliqiye.utils.springboot.autoconfigure.Jackson3JsonApiAutoConfiguration
|
||||
com.mingliqiye.utils.springboot.autoconfigure.JSONAAutoConfiguration
|
||||
com.mingliqiye.utils.springboot.autoconfigure.Okhttp3AutoConfiguration
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ 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.test
|
||||
~ CurrentFile log4j2.xml
|
||||
~ LastUpdate 2026-11-16 12:59:01
|
||||
~ UpdateUser MingLiPro
|
||||
-->
|
||||
|
||||
<Configuration status="WARN">
|
||||
<Appenders>
|
||||
<Console name="CONSOLE" target="SYSTEM_OUT">
|
||||
<PatternLayout
|
||||
pattern="%style{%d{yyyy-MM-dd HH:mm:ss.SSSSSSS}}{bright,magenta} %highlight{[%p]}{FATAL=white, ERROR=bright_red, WARN=bright_yellow, INFO=bright_green, DEBUG=bright_cyan, TRACE=bright_blue} [%style{%t}{bright,yellow}/%style{%c{1}}{bright,cyan}] -> %style{%m}{#EEDFCC}%n"/>
|
||||
</Console>
|
||||
<RollingFile name="FILE"
|
||||
fileName="log/current.log"
|
||||
filePattern="log/%d{yyyy/MM/dd}.log">
|
||||
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSSSSSS} %p %t/%c/%C.%M(%F:%L) --> %m%n"/>
|
||||
<Policies>
|
||||
<TimeBasedTriggeringPolicy interval="1" modulate="true"/>
|
||||
</Policies>
|
||||
</RollingFile>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="DEBUG">
|
||||
<AppenderRef ref="CONSOLE"/>
|
||||
<AppenderRef ref="FILE"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
Reference in New Issue
Block a user