Skip to content

Commit

Permalink
Merge pull request #40 from kintone/fix-negative-number-year
Browse files Browse the repository at this point in the history
fix: fix unintended serialization when year is a negative number
  • Loading branch information
0gr committed Oct 28, 2022
2 parents b61d75c + 5bf0412 commit 6314c16
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/kintone/client/RecordSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
class RecordSerializer extends StdSerializer<Record> {
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<FieldType> IGNORE_FIELD_TYPES;

Expand Down
31 changes: 31 additions & 0 deletions src/test/java/com/kintone/client/RecordSerializerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 6314c16

Please sign in to comment.