From c6860a3d9219507b64b858f6bc1f5d58a409cc1f Mon Sep 17 00:00:00 2001 From: tomohiro-okuyama <58939083+tomohiro-okuyama@users.noreply.github.com> Date: Thu, 27 Oct 2022 10:34:11 +0900 Subject: [PATCH 1/2] fix: fix unintended serialization when year is a negative number --- .../com/kintone/client/RecordSerializer.java | 4 +-- .../kintone/client/RecordSerializerTest.java | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/kintone/client/RecordSerializer.java b/src/main/java/com/kintone/client/RecordSerializer.java index e2dbbdf5..53e5ad52 100644 --- a/src/main/java/com/kintone/client/RecordSerializer.java +++ b/src/main/java/com/kintone/client/RecordSerializer.java @@ -27,10 +27,10 @@ class RecordSerializer extends StdSerializer { private static final long serialVersionUID = 8267967360812294563L; - private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("uuuu-MM-dd"); private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm"); private static final DateTimeFormatter DATETIME_FORMATTER = - DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'"); + DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm'Z'"); private static final Set IGNORE_FIELD_TYPES; diff --git a/src/test/java/com/kintone/client/RecordSerializerTest.java b/src/test/java/com/kintone/client/RecordSerializerTest.java index 14293238..b49f69b3 100644 --- a/src/test/java/com/kintone/client/RecordSerializerTest.java +++ b/src/test/java/com/kintone/client/RecordSerializerTest.java @@ -109,6 +109,14 @@ public void serialize_CREATED_TIME() throws IOException { assertThat(json).isEqualTo("{\"created_time\":{\"value\":\"2020-01-02T03:04Z\"}}"); } + @Test + public void serialize_CREATED_TIME_negativeNumberYear() throws IOException { + ZonedDateTime time = ZonedDateTime.of(-2020, 1, 2, 3, 4, 5, 6, ZoneOffset.UTC); + Record record = new Record().putField("created_time", new CreatedTimeFieldValue(time)); + String json = mapper.writeValueAsString(record); + assertThat(json).isEqualTo("{\"created_time\":{\"value\":\"-2020-01-02T03:04Z\"}}"); + } + @Test public void serialize_CREATED_TIME_empty() throws IOException { Record record = new Record().putField("created_time", new CreatedTimeFieldValue(null)); @@ -138,6 +146,13 @@ public void serialize_DATE() throws IOException { assertThat(json).isEqualTo("{\"date\":{\"value\":\"2020-01-02\"}}"); } + @Test + public void serialize_DATE_negativeNumberYear() throws IOException { + Record record = new Record().putField("date", new DateFieldValue(LocalDate.of(-2020, 1, 2))); + String json = mapper.writeValueAsString(record); + assertThat(json).isEqualTo("{\"date\":{\"value\":\"-2020-01-02\"}}"); + } + @Test public void serialize_DATE_empty() throws IOException { Record record = new Record().putField("date", new DateFieldValue(null)); @@ -153,6 +168,14 @@ public void serialize_DATETIME() throws IOException { assertThat(json).isEqualTo("{\"datetime\":{\"value\":\"2020-01-02T03:04Z\"}}"); } + @Test + public void serialize_DATETIME_negativeNumberYear() throws IOException { + ZonedDateTime value = ZonedDateTime.of(-2020, 1, 2, 3, 4, 5, 6, ZoneOffset.UTC); + Record record = new Record().putField("datetime", new DateTimeFieldValue(value)); + String json = mapper.writeValueAsString(record); + assertThat(json).isEqualTo("{\"datetime\":{\"value\":\"-2020-01-02T03:04Z\"}}"); + } + @Test public void serialize_DATETIME_empty() throws IOException { Record record = new Record().putField("datetime", new DateTimeFieldValue(null)); @@ -416,6 +439,14 @@ public void serialize_UPDATED_TIME() throws IOException { assertThat(json).isEqualTo("{\"updated_time\":{\"value\":\"2020-01-02T03:04Z\"}}"); } + @Test + public void serialize_UPDATED_TIME_negativeNumberYear() throws IOException { + ZonedDateTime time = ZonedDateTime.of(-2020, 1, 2, 3, 4, 5, 6, ZoneOffset.UTC); + Record record = new Record().putField("updated_time", new UpdatedTimeFieldValue(time)); + String json = mapper.writeValueAsString(record); + assertThat(json).isEqualTo("{\"updated_time\":{\"value\":\"-2020-01-02T03:04Z\"}}"); + } + @Test public void serialize_UPDATED_TIME_empty() throws IOException { Record record = new Record().putField("updated_time", new UpdatedTimeFieldValue(null)); From 5bf0412dff5dd3bbbb407e6c72234a17be89665b Mon Sep 17 00:00:00 2001 From: tomohiro-okuyama <58939083+tomohiro-okuyama@users.noreply.github.com> Date: Thu, 27 Oct 2022 10:35:05 +0900 Subject: [PATCH 2/2] chore: bump version to 1.4.1 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 66e2c57e..165ff591 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { id 'com.github.hierynomus.license' version '0.16.1' } -version = '1.4.0' +version = '1.4.1' sourceCompatibility = 1.8 targetCompatibility = 1.8