7 Commits

Author SHA1 Message Date
b0fce37a3e release: 1.0.4
Co-authored-by: ZhouXY108 <luquanlion@outlook.com>
Co-committed-by: ZhouXY108 <luquanlion@outlook.com>
2025-05-02 14:31:54 +08:00
b6017454c7 docs: 修改 MultiTypesException 文档描述
Co-authored-by: ZhouXY108 <luquanlion@outlook.com>
Co-committed-by: ZhouXY108 <luquanlion@outlook.com>
2025-05-02 14:04:51 +08:00
6d5da7ab32 chore: 修改注释中的拼写错误
Co-authored-by: ZhouXY108 <luquanlion@outlook.com>
Co-committed-by: ZhouXY108 <luquanlion@outlook.com>
2025-05-02 13:55:38 +08:00
473e1ce223 release: 1.0.3 2025-04-19 02:03:11 +08:00
3b9f0a30c2 chore: 更新依赖 2025-04-19 02:02:31 +08:00
34076294a7 fix: 修复 JDK17+ 环境下测试用例 PagingAndSortingQueryParamsTests#testGson 不通过的问题
该用例在 JDK17+ 环境下使用 gson 进行序列化时,报 `com.google.gson.JsonIOException: Failed making field 'java.time.LocalDateTime#date' accessible; either increase its visibility or write a custom TypeAdapter for its declaring type`。

See: https://github.com/google/gson/blob/main/Troubleshooting.md#reflection-inaccessible
2025-04-19 02:01:32 +08:00
c6df5cd925 docs: fix param name 2025-04-19 02:00:52 +08:00
5 changed files with 23 additions and 13 deletions

View File

@@ -6,7 +6,7 @@
<groupId>xyz.zhouxy.plusone</groupId>
<artifactId>plusone-commons</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
<properties>
<!-- Basic properties -->

View File

@@ -29,7 +29,7 @@ import xyz.zhouxy.plusone.commons.base.IWithCode;
* 异常实现 {@link MultiTypesException} 的 {@link #getType} 方法,返回对应的场景类型。
* </p>
* <p>
* 表示场景类型的枚举实现 {@link ExceptionType},其中的工厂方法用于创建类型对象
* 表示场景类型的枚举实现 {@link ExceptionType},其中的工厂方法用于创建对应类型的异常
* </p>
*
* <pre>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 the original author or authors.
* Copyright 2023-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2024 the original author or authors.
* Copyright 2024-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -184,24 +184,34 @@ public class PagingAndSortingQueryParamsTests {
assertThrows(IllegalArgumentException.class, () -> queryParams.buildPagingParams()); // NOSONAR
}
static final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
@Test
void testGson() throws Exception {
void testGson() {
Gson gson = new GsonBuilder()
.registerTypeAdapter(LocalDate.class, new TypeAdapter<LocalDate>() {
@Override
public void write(JsonWriter out, LocalDate value) throws IOException {
out.value(dateFormatter.format(value));
out.value(DateTimeFormatter.ISO_DATE.format(value));
}
@Override
public LocalDate read(JsonReader in) throws IOException {
return LocalDate.parse(in.nextString(), dateFormatter);
return LocalDate.parse(in.nextString(), DateTimeFormatter.ISO_DATE);
}
})
.registerTypeAdapter(LocalDateTime.class, new TypeAdapter<LocalDateTime>() {
@Override
public void write(JsonWriter out, LocalDateTime value) throws IOException {
out.value(DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(value));
}
@Override
public LocalDateTime read(JsonReader in) throws IOException {
return LocalDateTime.parse(in.nextString(), DateTimeFormatter.ISO_LOCAL_DATE_TIME);
}
})
.create();
try (SqlSession session = sqlSessionFactory.openSession()) {
AccountQueryParams params = gson.fromJson(JSON_STR, AccountQueryParams.class);
@@ -212,7 +222,7 @@ public class PagingAndSortingQueryParamsTests {
List<AccountVO> list = accountQueries.queryAccountList(params, pagingParams);
long count = accountQueries.countAccount(params);
PageResult<AccountVO> accountPageResult = PageResult.of(list, count);
// TODO [修复] 从 JDK 17 开始,也允许使用反射访问内部字段,所以这里会报错。参考 https://github.com/google/gson/blob/main/Troubleshooting.md#reflection-inaccessible
log.info(gson.toJson(accountPageResult));
assertEquals(Lists.newArrayList(
@@ -227,7 +237,7 @@ public class PagingAndSortingQueryParamsTests {
}
AccountQueryParams queryParams = gson.fromJson(WRONG_JSON_STR, AccountQueryParams.class);
assertThrows(IllegalArgumentException.class, () -> queryParams.buildPagingParams()); // NOSONAR
assertThrows(IllegalArgumentException.class, queryParams::buildPagingParams);
}
}

View File

@@ -400,7 +400,7 @@ class DateTimeToolsTests {
// ================================
// ================================
// #region - ZondId <--> DateTimeZone
// #region - ZoneId <--> DateTimeZone
// ================================
@Test
@@ -412,7 +412,7 @@ class DateTimeToolsTests {
}
// ================================
// #endregion - ZondId <--> DateTimeZone
// #endregion - ZoneId <--> DateTimeZone
// ================================
// ================================