Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.GsonBuilder;
import org.junit.jupiter.api.Test;

import java.time.Instant;
import java.time.LocalDateTime;

public class JsonApprovalsTest
Expand Down Expand Up @@ -38,6 +39,26 @@ public void setLocalDate(LocalDateTime localDate)
}
private LocalDateTime localDate;
}

@Test
void nullInstantTest()
{
InstantWrapper instantWrapper = new InstantWrapper();
JsonApprovals.verifyAsJson(instantWrapper, g -> g.serializeNulls());
}
private class InstantWrapper
{
public Instant getInstant()
{
return instant;
}

public void setInstant(Instant instant)
{
this.instant = instant;
}
private Instant instant;
}
@Test
void verifyJsonReorderWithoutArray()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"instant": null
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,14 @@ public static class InstantAdapter extends TypeAdapter<Instant>
@Override
public void write(JsonWriter jsonWriter, Instant instant) throws IOException
{
jsonWriter.value(instant.toString());
if (instant == null)
{
jsonWriter.nullValue();
}
else
{
jsonWriter.value("" + instant);
}
}

@Override
Expand Down
Loading