Ensuring that UTC date adapter serializes nulls correctly
This commit is contained in:
parent
f0f9ce42f4
commit
0c3b9670f0
@ -37,10 +37,11 @@ public final class UtcDateTypeAdapter extends TypeAdapter<Date> {
|
||||
public void write(JsonWriter out, Date date) throws IOException {
|
||||
if (date == null) {
|
||||
out.nullValue();
|
||||
}
|
||||
} else {
|
||||
String value = format(date, true, UTC_TIME_ZONE);
|
||||
out.value(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date read(JsonReader in) throws IOException {
|
||||
|
@ -71,4 +71,9 @@ public final class UtcDateTypeAdapterTest extends TestCase {
|
||||
Date actual = gson.fromJson(expectedJson, Date.class);
|
||||
assertEquals(expected.getTime(), actual.getTime());
|
||||
}
|
||||
|
||||
public void testNullDateSerialization() {
|
||||
String json = gson.toJson(null, Date.class);
|
||||
assertEquals("null", json);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user