Skip to content

Commit

Permalink
- B verifyAsJson() handles null LocalTimeDates.
Browse files Browse the repository at this point in the history
Fixes #531
  • Loading branch information
ScottBob committed Jul 11, 2024
1 parent bd7021a commit 4c32b03
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.approvaltests;

import com.spun.util.Wrapper;
import org.junit.jupiter.api.Test;

import java.time.LocalDateTime;

public class JsonApprovalsTest {
@Test
void nullDateTest() {
LocalDateWrapper localDateWrapper = new LocalDateWrapper();
JsonApprovals.verifyAsJson(localDateWrapper, g -> g.serializeNulls());
}

private class LocalDateWrapper {
public LocalDateTime getLocalDate() {
return localDate;
}

public void setLocalDate(LocalDateTime localDate) {
this.localDate = localDate;
}

private LocalDateTime localDate;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"localDate": null
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ public static class LocalDateTimeAdapter extends TypeAdapter<LocalDateTime>
@Override
public void write(JsonWriter jsonWriter, LocalDateTime instant) throws IOException
{
jsonWriter.value(instant.toString());
if (instant == null) {
jsonWriter.nullValue();
} else {
jsonWriter.value("" + instant);
}
}
@Override
public LocalDateTime read(JsonReader jsonReader) throws IOException
Expand Down

0 comments on commit 4c32b03

Please sign in to comment.