diff --git a/mica-core/build.gradle b/mica-core/build.gradle index 25b293560..7e46646fd 100644 --- a/mica-core/build.gradle +++ b/mica-core/build.gradle @@ -1,6 +1,6 @@ dependencies { - api "org.springframework:spring-context" api "com.fasterxml.jackson.core:jackson-databind" + implementation "org.springframework:spring-context" compileOnly "org.springframework:spring-web" compileOnly "jakarta.validation:jakarta.validation-api" compileOnly "io.swagger:swagger-annotations" diff --git a/mica-core/src/main/java/net/dreamlu/mica/core/utils/JsonUtil.java b/mica-core/src/main/java/net/dreamlu/mica/core/utils/JsonUtil.java index e3c0f9d35..36ea043a1 100644 --- a/mica-core/src/main/java/net/dreamlu/mica/core/utils/JsonUtil.java +++ b/mica-core/src/main/java/net/dreamlu/mica/core/utils/JsonUtil.java @@ -29,7 +29,6 @@ import com.fasterxml.jackson.databind.type.MapType; import net.dreamlu.mica.core.function.CheckedConsumer; import org.springframework.lang.Nullable; -import org.springframework.util.ObjectUtils; import java.io.IOException; import java.io.InputStream; @@ -220,7 +219,7 @@ public static JsonNode readTree(JsonParser jsonParser) { */ @Nullable public static T readValue(@Nullable byte[] content, Class valueType) { - if (ObjectUtils.isEmpty(content)) { + if (content == null || content.length == 0) { return null; } try { @@ -301,7 +300,7 @@ public static T readValue(@Nullable Reader reader, Class valueType) { */ @Nullable public static T readValue(@Nullable byte[] content, TypeReference typeReference) { - if (ObjectUtils.isEmpty(content)) { + if (content == null || content.length == 0) { return null; } try { @@ -381,7 +380,7 @@ public static T readValue(@Nullable Reader reader, TypeReference typeRefe */ @Nullable public static T readValue(@Nullable byte[] content, JavaType javaType) { - if (ObjectUtils.isEmpty(content)) { + if (content == null || content.length == 0) { return null; } try { @@ -531,7 +530,7 @@ public static JavaType getParametricType(Class parametrized, JavaType... para * @return 集合 */ public static List readList(@Nullable byte[] content, Class elementClass) { - if (ObjectUtils.isEmpty(content)) { + if (content == null || content.length == 0) { return Collections.emptyList(); } try { @@ -697,7 +696,7 @@ public static Map readMap(@Nullable String content, Class valu * @return 集合 */ public static Map readMap(@Nullable byte[] content, Class keyClass, Class valueClass) { - if (ObjectUtils.isEmpty(content)) { + if (content == null || content.length == 0) { return Collections.emptyMap(); } try { diff --git a/mica-http/src/main/java/net/dreamlu/mica/http/HttpLogger.java b/mica-http/src/main/java/net/dreamlu/mica/http/HttpLogger.java index 3dc8d8fba..49565a565 100644 --- a/mica-http/src/main/java/net/dreamlu/mica/http/HttpLogger.java +++ b/mica-http/src/main/java/net/dreamlu/mica/http/HttpLogger.java @@ -46,7 +46,7 @@ public void log(@Nonnull String message) { @Override public void log(@Nonnull String message) { // 统一添加前缀,方便在茫茫日志中查看 - System.out.printf("HttpLogger: %s\n", message); + System.out.println("HttpLogger: " + message); } }; diff --git a/mica-http/src/test/java/net/dreamlu/HttpRequestDemo.java b/mica-http/src/test/java/net/dreamlu/HttpRequestDemo.java index 55bea01a6..debec3c49 100644 --- a/mica-http/src/test/java/net/dreamlu/HttpRequestDemo.java +++ b/mica-http/src/test/java/net/dreamlu/HttpRequestDemo.java @@ -17,6 +17,7 @@ package net.dreamlu; import com.fasterxml.jackson.databind.JsonNode; +import lombok.extern.slf4j.Slf4j; import net.dreamlu.mica.core.utils.Base64Util; import net.dreamlu.mica.http.HttpLogger; import net.dreamlu.mica.http.HttpRequest; @@ -33,6 +34,7 @@ * * @author L.cm */ +@Slf4j public class HttpRequestDemo { public void doc() { @@ -40,10 +42,12 @@ public void doc() { HttpRequest.setGlobalLog(LogLevel.BODY); // 设置控制台日志,用于没有日志依赖的 sdk 开发时使用 HttpRequest.setGlobalLog(HttpLogger.Console, LogLevel.BODY); + // 设置为自己的日志,避免需要配置 net.dreamlu.mica.http 包日志等级 + HttpRequest.setGlobalLog(log::info); // 同步请求 url,方法支持 get、post、patch、put、delete HttpRequest.get("https://www.baidu.com") - .useSlf4jLog() //使用 Slf4j 日志,同类的有 .useConsoleLog(),日志级别为 BODY + .useSlf4jLog() //使用 Slf4j 日志,同类的有 .useConsoleLog(),.useLog(log::info),日志级别为 BODY .addHeader("x-account-id", "mica001") // 添加 header .addCookie(new Cookie.Builder() // 添加 cookie .name("sid")