From c28157bfa5521508e3275d81149d3dd055eb3c69 Mon Sep 17 00:00:00 2001 From: Hamm Date: Thu, 20 Jun 2024 15:16:13 +0800 Subject: [PATCH 1/4] refactor(open-request): use `@NotBlank` instead of `@NotNull` for non-null string checks Update all non-null annotations in `OpenRequest.java` from `@NotNull` to `@NotBlank`, which is more appropriate for validating strings that must contain at least one character and cannot be null. --- .../src/main/java/cn/hamm/airpower/open/OpenRequest.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/airpower-core/src/main/java/cn/hamm/airpower/open/OpenRequest.java b/airpower-core/src/main/java/cn/hamm/airpower/open/OpenRequest.java index 5323009..7b744d6 100644 --- a/airpower-core/src/main/java/cn/hamm/airpower/open/OpenRequest.java +++ b/airpower-core/src/main/java/cn/hamm/airpower/open/OpenRequest.java @@ -53,19 +53,19 @@ public class OpenRequest { /** *

加密后的业务数据

*/ - @NotNull(message = "业务数据包体不能为空") + @NotBlank(message = "业务数据包体不能为空") private String content; /** *

签名字符串

*/ - @NotNull(message = "签名字符串不能为空") + @NotBlank(message = "签名字符串不能为空") private String signature; /** *

请求随机串

*/ - @NotNull(message = "请求随机串不能为空") + @NotBlank(message = "请求随机串不能为空") private String nonce; /** @@ -102,8 +102,9 @@ public class OpenRequest { * @param clazz 业务数据对象类型 */ public final > T parse(Class clazz) { + String json = decodeContent(); try { - return Json.parse(decodeContent(), clazz); + return Json.parse(json, clazz); } catch (Exception e) { ServiceError.JSON_DECODE_FAIL.show(); throw new ServiceException(e); -- Gitee From 648619380a9eb31ac8c1efea15a37d4bc5e5237a Mon Sep 17 00:00:00 2001 From: Hamm Date: Thu, 20 Jun 2024 21:21:14 +0800 Subject: [PATCH 2/4] fix(core): optimize Json class by configuring ObjectMapper for null handling Refactor the Json class to utilize ObjectMapper configurations for serialization and deserialization features. This update ensures that null values are properly handled during JSON parsing operations, improving the robustness of the data transformation processes within the airpower-core module. BREAKING CHANGE: The adjustment of ObjectMapper settings for null inclusion could affect existing consumers of the parse2Map and parse2MapList methods that rely on previous behavior of not including null values. Signed-off-by: Hamm --- .../src/main/java/cn/hamm/airpower/model/Json.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/airpower-core/src/main/java/cn/hamm/airpower/model/Json.java b/airpower-core/src/main/java/cn/hamm/airpower/model/Json.java index b4f11f1..ed56cf0 100644 --- a/airpower-core/src/main/java/cn/hamm/airpower/model/Json.java +++ b/airpower-core/src/main/java/cn/hamm/airpower/model/Json.java @@ -12,6 +12,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; import lombok.Data; import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; @@ -179,8 +180,6 @@ public class Json { * @return Map */ public static Map parse2Map(String json) { - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); try { TypeReference> typeRef = new TypeReference<>() { }; @@ -198,8 +197,6 @@ public class Json { * @return List */ public static List> parse2MapList(String json) { - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); try { TypeReference>> typeRef = new TypeReference<>() { }; @@ -235,6 +232,10 @@ public class Json { objectMapper = new ObjectMapper(); // 忽略未声明的属性 objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + // 忽略值为null的属性 + objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + // 忽略没有属性的类 + objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); } return objectMapper; } -- Gitee From 095e824cce03f2e252335dd378cbfaeabe363f48 Mon Sep 17 00:00:00 2001 From: Hamm Date: Mon, 24 Jun 2024 15:12:43 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix(json):=20=E4=BF=AE=E5=A4=8D`JSON`?= =?UTF-8?q?=E5=BA=8F=E5=88=97=E5=8C=96`Map`=E5=A4=B1=E8=B4=A5=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hamm --- airpower-core/src/main/java/cn/hamm/airpower/model/Json.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/airpower-core/src/main/java/cn/hamm/airpower/model/Json.java b/airpower-core/src/main/java/cn/hamm/airpower/model/Json.java index ed56cf0..04935aa 100644 --- a/airpower-core/src/main/java/cn/hamm/airpower/model/Json.java +++ b/airpower-core/src/main/java/cn/hamm/airpower/model/Json.java @@ -183,7 +183,7 @@ public class Json { try { TypeReference> typeRef = new TypeReference<>() { }; - return objectMapper.readValue(json, typeRef); + return getObjectMapper().readValue(json, typeRef); } catch (Exception exception) { log.error(exception.getMessage()); throw new ServiceException(exception); @@ -200,7 +200,7 @@ public class Json { try { TypeReference>> typeRef = new TypeReference<>() { }; - return objectMapper.readValue(json, typeRef); + return getObjectMapper().readValue(json, typeRef); } catch (Exception exception) { log.error(exception.getMessage()); throw new ServiceException(exception); -- Gitee From e0dcbafcd7154d756f7d85ffc4f3e2fefb28c775 Mon Sep 17 00:00:00 2001 From: Hamm Date: Mon, 24 Jun 2024 15:39:52 +0800 Subject: [PATCH 4/4] =?UTF-8?q?release(v2.0.7):=20=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E4=BA=86`v2.0.7`=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hamm --- airpower-core/pom.xml | 4 ++-- pom.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/airpower-core/pom.xml b/airpower-core/pom.xml index 64f8bf4..cb5bb28 100644 --- a/airpower-core/pom.xml +++ b/airpower-core/pom.xml @@ -5,10 +5,10 @@ cn.hamm airpower - 2.0.6 + 2.0.7 airpower-core - 2.0.6 + 2.0.7 airpower-core AirPower is a fast backend development tool based on SpringBoot3 and JPA. It's the core of AirPower. diff --git a/pom.xml b/pom.xml index 139da9c..a32f372 100644 --- a/pom.xml +++ b/pom.xml @@ -4,11 +4,11 @@ 4.0.0 cn.hamm airpower - 2.0.6 + 2.0.7 airpower AirPower is a fast backend development tool based on SpringBoot3 and JPA. - 2.0.6 + 2.0.7 UTF-8 UTF-8 UTF-8 -- Gitee