Compare commits
2 Commits
5bf7063c05
...
45dc105dd0
Author | SHA1 | Date | |
---|---|---|---|
45dc105dd0 | |||
c779430e6f |
@@ -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(
|
||||
|
Reference in New Issue
Block a user