2 Commits

Author SHA1 Message Date
45dc105dd0 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-16 14:52:16 +08:00
c779430e6f chore: 更新依赖
依赖:
- guava: `33.4.0-jre` 更新到 `33.4.2-jre`;
- joda-time: `2.13.0` 更新到 `2.14.0`;

*测试依赖:
- junit: `5.11.4` 更新到 `5.12.1`;
- hutool: `5.8.35` 更新到 `5.8.37`;
- jackson: `2.18.2` 更新到 `2.18.3`;
2025-04-16 14:32:12 +08:00

View File

@@ -184,8 +184,6 @@ public class PagingAndSortingQueryParamsTests {
assertThrows(IllegalArgumentException.class, queryParams::buildPagingParams);
}
static final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
@Test
void testGson() {
Gson gson = new GsonBuilder()
@@ -193,15 +191,27 @@ public class PagingAndSortingQueryParamsTests {
@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(