FIX: Backward compatibility to ebean 11

This commit is contained in:
Roland Praml
2021-11-29 13:30:56 +01:00
parent 3883db84b5
commit 4152ae9814
2 changed files with 17 additions and 1 deletions
@@ -10,6 +10,7 @@ import java.sql.Timestamp;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeParseException;
/**
* ScalarType for java.sql.Timestamp.
@@ -62,7 +63,11 @@ final class ScalarTypeLocalDateTime extends ScalarTypeBaseDateTime<LocalDateTime
@Override
public LocalDateTime parse(String value) {
return LocalDateTime.parse(value);
try {
return LocalDateTime.parse(value);
} catch (DateTimeParseException pe) {
return super.parse(value);
}
}
@Override
@@ -123,4 +123,15 @@ public class ScalarTypeLocalDateTimeTest {
LocalDateTime value = typeIso.fromJsonISO8601(asJson);
assertThat(localDateTime).isEqualToIgnoringNanos(value);
}
@Test
public void testParseEbean11() {
ScalarTypeLocalDateTime typeDefault = new ScalarTypeLocalDateTime(JsonConfig.DateTime.ISO8601);
LocalDateTime fromMillis = typeDefault.parse("1517627106000");
LocalDateTime fromIso= typeDefault.parse("2018-02-03T04:05:06");
assertThat(fromMillis).isEqualToIgnoringNanos(fromIso);
}
}