Compare commits
4 Commits
v1.0.x
...
f4c1f42a0b
Author | SHA1 | Date | |
---|---|---|---|
f4c1f42a0b | |||
e7e5a51718 | |||
9ab9d45a53 | |||
a901f3231d |
2
pom.xml
2
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>xyz.zhouxy.plusone</groupId>
|
<groupId>xyz.zhouxy.plusone</groupId>
|
||||||
<artifactId>plusone-commons</artifactId>
|
<artifactId>plusone-commons</artifactId>
|
||||||
<version>1.0.4</version>
|
<version>1.0.3</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<!-- Basic properties -->
|
<!-- Basic properties -->
|
||||||
|
@@ -29,7 +29,7 @@ import xyz.zhouxy.plusone.commons.base.IWithCode;
|
|||||||
* 异常实现 {@link MultiTypesException} 的 {@link #getType} 方法,返回对应的场景类型。
|
* 异常实现 {@link MultiTypesException} 的 {@link #getType} 方法,返回对应的场景类型。
|
||||||
* </p>
|
* </p>
|
||||||
* <p>
|
* <p>
|
||||||
* 表示场景类型的枚举实现 {@link ExceptionType},其中的工厂方法用于创建对应类型的异常。
|
* 表示场景类型的枚举实现 {@link ExceptionType},其中的工厂方法用于创建类型对象。
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2023-2025 the original author or authors.
|
* Copyright 2023-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2024-2025 the original author or authors.
|
* Copyright 2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -184,34 +184,24 @@ public class PagingAndSortingQueryParamsTests {
|
|||||||
assertThrows(IllegalArgumentException.class, () -> queryParams.buildPagingParams()); // NOSONAR
|
assertThrows(IllegalArgumentException.class, () -> queryParams.buildPagingParams()); // NOSONAR
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testGson() {
|
void testGson() throws Exception {
|
||||||
Gson gson = new GsonBuilder()
|
Gson gson = new GsonBuilder()
|
||||||
.registerTypeAdapter(LocalDate.class, new TypeAdapter<LocalDate>() {
|
.registerTypeAdapter(LocalDate.class, new TypeAdapter<LocalDate>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(JsonWriter out, LocalDate value) throws IOException {
|
public void write(JsonWriter out, LocalDate value) throws IOException {
|
||||||
out.value(DateTimeFormatter.ISO_DATE.format(value));
|
out.value(dateFormatter.format(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LocalDate read(JsonReader in) throws IOException {
|
public LocalDate read(JsonReader in) throws IOException {
|
||||||
return LocalDate.parse(in.nextString(), DateTimeFormatter.ISO_DATE);
|
return LocalDate.parse(in.nextString(), dateFormatter);
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
.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();
|
.create();
|
||||||
try (SqlSession session = sqlSessionFactory.openSession()) {
|
try (SqlSession session = sqlSessionFactory.openSession()) {
|
||||||
AccountQueryParams params = gson.fromJson(JSON_STR, AccountQueryParams.class);
|
AccountQueryParams params = gson.fromJson(JSON_STR, AccountQueryParams.class);
|
||||||
@@ -222,7 +212,7 @@ public class PagingAndSortingQueryParamsTests {
|
|||||||
List<AccountVO> list = accountQueries.queryAccountList(params, pagingParams);
|
List<AccountVO> list = accountQueries.queryAccountList(params, pagingParams);
|
||||||
long count = accountQueries.countAccount(params);
|
long count = accountQueries.countAccount(params);
|
||||||
PageResult<AccountVO> accountPageResult = PageResult.of(list, count);
|
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));
|
log.info(gson.toJson(accountPageResult));
|
||||||
|
|
||||||
assertEquals(Lists.newArrayList(
|
assertEquals(Lists.newArrayList(
|
||||||
@@ -237,7 +227,7 @@ public class PagingAndSortingQueryParamsTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AccountQueryParams queryParams = gson.fromJson(WRONG_JSON_STR, AccountQueryParams.class);
|
AccountQueryParams queryParams = gson.fromJson(WRONG_JSON_STR, AccountQueryParams.class);
|
||||||
assertThrows(IllegalArgumentException.class, queryParams::buildPagingParams);
|
assertThrows(IllegalArgumentException.class, () -> queryParams.buildPagingParams()); // NOSONAR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -400,7 +400,7 @@ class DateTimeToolsTests {
|
|||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
// ================================
|
// ================================
|
||||||
// #region - ZoneId <--> DateTimeZone
|
// #region - ZondId <--> DateTimeZone
|
||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -412,7 +412,7 @@ class DateTimeToolsTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ================================
|
// ================================
|
||||||
// #endregion - ZoneId <--> DateTimeZone
|
// #endregion - ZondId <--> DateTimeZone
|
||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
// ================================
|
// ================================
|
||||||
|
Reference in New Issue
Block a user