forked from plusone/plusone-commons
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
473e1ce223 | |||
3b9f0a30c2 | |||
34076294a7 | |||
c6df5cd925 |
12
pom.xml
12
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.2</version>
|
<version>1.0.3</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<!-- Basic properties -->
|
<!-- Basic properties -->
|
||||||
@@ -16,18 +16,18 @@
|
|||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
|
||||||
<!-- Versions of compile dependencies -->
|
<!-- Versions of compile dependencies -->
|
||||||
<guava.version>33.4.0-jre</guava.version>
|
<guava.version>33.4.2-jre</guava.version>
|
||||||
<joda-time.version>2.13.0</joda-time.version>
|
<joda-time.version>2.14.0</joda-time.version>
|
||||||
|
|
||||||
<!-- Versions of test dependencies -->
|
<!-- Versions of test dependencies -->
|
||||||
<commons-lang3.version>3.17.0</commons-lang3.version>
|
<commons-lang3.version>3.17.0</commons-lang3.version>
|
||||||
<logback.version>1.2.13</logback.version>
|
<logback.version>1.2.13</logback.version>
|
||||||
<junit.version>5.11.4</junit.version>
|
<junit.version>5.12.1</junit.version>
|
||||||
<lombok.version>1.18.36</lombok.version>
|
<lombok.version>1.18.36</lombok.version>
|
||||||
<hutool.version>5.8.35</hutool.version>
|
<hutool.version>5.8.37</hutool.version>
|
||||||
<mybatis.version>3.5.19</mybatis.version>
|
<mybatis.version>3.5.19</mybatis.version>
|
||||||
<h2.version>2.2.224</h2.version>
|
<h2.version>2.2.224</h2.version>
|
||||||
<jackson.version>2.18.2</jackson.version>
|
<jackson.version>2.18.3</jackson.version>
|
||||||
<gson.version>2.12.1</gson.version>
|
<gson.version>2.12.1</gson.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
@@ -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");
|
* 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,7 +184,7 @@ public class DateTimeTools {
|
|||||||
/**
|
/**
|
||||||
* 使用指定时区,将 {@link LocalDateTime} 对象转换为 {@link Instant} 对象
|
* 使用指定时区,将 {@link LocalDateTime} 对象转换为 {@link Instant} 对象
|
||||||
*
|
*
|
||||||
* @param LocalDateTime {@link LocalDateTime} 对象
|
* @param localDateTime {@link LocalDateTime} 对象
|
||||||
* @param zone 时区
|
* @param zone 时区
|
||||||
* @return {@link Instant} 对象
|
* @return {@link Instant} 对象
|
||||||
*/
|
*/
|
||||||
|
@@ -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");
|
* 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,24 +184,34 @@ 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() throws Exception {
|
void testGson() {
|
||||||
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(dateFormatter.format(value));
|
out.value(DateTimeFormatter.ISO_DATE.format(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LocalDate read(JsonReader in) throws IOException {
|
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();
|
.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);
|
||||||
@@ -212,6 +222,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);
|
||||||
|
|
||||||
log.info(gson.toJson(accountPageResult));
|
log.info(gson.toJson(accountPageResult));
|
||||||
|
|
||||||
assertEquals(Lists.newArrayList(
|
assertEquals(Lists.newArrayList(
|
||||||
@@ -226,7 +237,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()); // NOSONAR
|
assertThrows(IllegalArgumentException.class, queryParams::buildPagingParams);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user