Skip to content

Commit 4876407

Browse files
committed
Update BeanAdapter.
1 parent cd6036f commit 4876407

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
subprojects {
1616
group = 'org.httprpc'
17-
version = '4.9.4'
17+
version = '4.9.5'
1818

1919
apply plugin: 'java-library'
2020

kilo-client/src/main/java/org/httprpc/kilo/beans/BeanAdapter.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.time.LocalDateTime;
3535
import java.time.LocalTime;
3636
import java.time.Period;
37+
import java.time.format.DateTimeParseException;
3738
import java.time.temporal.TemporalAccessor;
3839
import java.time.temporal.TemporalAmount;
3940
import java.util.AbstractList;
@@ -1018,7 +1019,13 @@ private static Object toRawType(Object value, Class<?> type) {
10181019
} else if (type == LocalTime.class) {
10191020
return LocalTime.parse(value.toString());
10201021
} else if (type == LocalDateTime.class) {
1021-
return LocalDateTime.parse(value.toString());
1022+
var text = value.toString();
1023+
1024+
try {
1025+
return LocalDateTime.parse(text);
1026+
} catch (DateTimeParseException exception) {
1027+
return LocalDateTime.of(LocalDate.parse(text), LocalTime.MIDNIGHT);
1028+
}
10221029
} else if (type == Duration.class) {
10231030
if (value instanceof Number number) {
10241031
return Duration.ofMillis(number.longValue());

kilo-client/src/test/java/org/httprpc/kilo/beans/BeanAdapterTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ public void testTemporalAccessorCoercion() {
239239
assertEquals(LocalDate.parse("2018-06-28"), BeanAdapter.coerce("2018-06-28", LocalDate.class));
240240
assertEquals(LocalTime.parse("10:45"), BeanAdapter.coerce("10:45", LocalTime.class));
241241
assertEquals(LocalDateTime.parse("2018-06-28T10:45"), BeanAdapter.coerce("2018-06-28T10:45", LocalDateTime.class));
242+
assertEquals(LocalDateTime.of(LocalDate.of(2018, 6, 28), LocalTime.MIDNIGHT), BeanAdapter.coerce("2018-06-28", LocalDateTime.class));
242243
}
243244

244245
@Test

0 commit comments

Comments
 (0)