Skip to content

Commit

Permalink
deserialize datetime and time without fraction seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
jenschude committed Aug 8, 2023
1 parent 6fbd45e commit d9588eb
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public class AtrributeDeserializer extends JsonDeserializer<AttributeImpl> {

private static Pattern p = Pattern.compile("^[0-9]");
private static Pattern dateTime = Pattern
.compile("^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}[.][0-9]{1,6}");
.compile("^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]{1,6})?");
private static Pattern date = Pattern.compile("^[0-9]{4}-[0-9]{2}-[0-9]{2}");
private static Pattern time = Pattern.compile("^[0-9]{2}:[0-9]{2}:[0-9]{2}[.][0-9]{1,6}");
private static Pattern time = Pattern.compile("^[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]{1,6})?");

private final boolean deserializeAsDate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public class CustomFieldDeserializer extends JsonDeserializer<FieldContainerImpl

private static Pattern p = Pattern.compile("^[0-9]");
private static Pattern dateTime = Pattern
.compile("^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}[.][0-9]{1,6}");
.compile("^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]{1,6})?");
private static Pattern date = Pattern.compile("^[0-9]{4}-[0-9]{2}-[0-9]{2}");
private static Pattern time = Pattern.compile("^[0-9]{2}:[0-9]{2}:[0-9]{2}[.][0-9]{1,6}");
private static Pattern time = Pattern.compile("^[0-9]{2}:[0-9]{2}:[0-9]{2}([.][0-9]{1,6})?");

private final boolean deserializeAsDate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ public void attributes() throws IOException {
localDate -> assertThat(localDate).isEqualTo("2020-01-01"));
assertThat(attributes.get("time")).isInstanceOfSatisfying(LocalTime.class,
localTime -> assertThat(localTime).isEqualTo("13:15:00.123"));
assertThat(attributes.get("time-simple")).isInstanceOfSatisfying(LocalTime.class,
localTime -> assertThat(localTime).isEqualTo("13:15:00"));
assertThat(attributes.get("datetime")).isInstanceOfSatisfying(ZonedDateTime.class,
dateTime -> assertThat(dateTime).isEqualTo("2020-01-01T13:15:00.123Z"));
assertThat(attributes.get("datetime-simple")).isInstanceOfSatisfying(ZonedDateTime.class,
dateTime -> assertThat(dateTime).isEqualTo("2020-01-01T13:15:00Z"));
assertThat(attributes.get("boolean")).isInstanceOfSatisfying(Boolean.class,
aBoolean -> assertThat(aBoolean).isTrue());
assertThat(attributes.get("integer")).isInstanceOfSatisfying(Long.class,
Expand Down Expand Up @@ -182,6 +186,10 @@ public void attributesAsDateFalse() throws IOException {
localTime -> assertThat(localTime).isEqualTo("13:15:00.123"));
assertThat(attributes.get("datetime").getValue()).isInstanceOfSatisfying(String.class,
dateTime -> assertThat(dateTime).isEqualTo("2020-01-01T13:15:00.123Z"));
assertThat(attributes.get("time-simple").getValue()).isInstanceOfSatisfying(String.class,
localTime -> assertThat(localTime).isEqualTo("13:15:00"));
assertThat(attributes.get("datetime-simple").getValue()).isInstanceOfSatisfying(String.class,
dateTime -> assertThat(dateTime).isEqualTo("2020-01-01T13:15:00Z"));
assertThat(attributes.get("date").withAttribute(AttributeAccessor::asDate))
.isInstanceOfSatisfying(LocalDate.class, localDate -> assertThat(localDate).isEqualTo("2020-01-01"));
assertThat(attributes.get("time").withAttribute(AttributeAccessor::asTime))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public void fields() throws IOException {
localTime -> assertThat(localTime).isEqualTo("13:15:00.123"));
assertThat(fields.get("datetime")).isInstanceOfSatisfying(ZonedDateTime.class,
dateTime -> assertThat(dateTime).isEqualTo("2020-01-01T13:15:00.123Z"));
assertThat(fields.get("time-simple")).isInstanceOfSatisfying(LocalTime.class,
localTime -> assertThat(localTime).isEqualTo("13:15:00"));
assertThat(fields.get("datetime-simple")).isInstanceOfSatisfying(ZonedDateTime.class,
dateTime -> assertThat(dateTime).isEqualTo("2020-01-01T13:15:00Z"));
assertThat(fields.get("boolean")).isInstanceOfSatisfying(Boolean.class,
aBoolean -> assertThat(aBoolean).isTrue());
assertThat(fields.get("integer")).isInstanceOfSatisfying(Long.class,
Expand Down Expand Up @@ -106,6 +110,10 @@ public void fieldsAsDateFalse() throws IOException {
localTime -> assertThat(localTime).isEqualTo("13:15:00.123"));
assertThat(fields.get("datetime")).isInstanceOfSatisfying(String.class,
dateTime -> assertThat(dateTime).isEqualTo("2020-01-01T13:15:00.123Z"));
assertThat(fields.get("time-simple")).isInstanceOfSatisfying(String.class,
localTime -> assertThat(localTime).isEqualTo("13:15:00"));
assertThat(fields.get("datetime-simple")).isInstanceOfSatisfying(String.class,
dateTime -> assertThat(dateTime).isEqualTo("2020-01-01T13:15:00Z"));

assertThat(fields.get("boolean")).isInstanceOfSatisfying(Boolean.class,
aBoolean -> assertThat(aBoolean).isTrue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,18 @@
"name": "time",
"value": "13:15:00.123"
},
{
"name": "time-simple",
"value": "13:15:00"
},
{
"name": "datetime",
"value": "2020-01-01T13:15:00.123Z"
},
{
"name": "datetime-simple",
"value": "2020-01-01T13:15:00Z"
},
{
"name": "boolean",
"value": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
},
"date": "2020-01-01",
"time": "13:15:00.123",
"time-simple": "13:15:00",
"datetime": "2020-01-01T13:15:00.123Z",
"datetime-simple": "2020-01-01T13:15:00Z",
"boolean": true,
"set-text": [
"foo"
Expand Down

0 comments on commit d9588eb

Please sign in to comment.