Skip to content

Commit

Permalink
Refactor switch-case to if-else in UtcDateTypeAdapter (#2760)
Browse files Browse the repository at this point in the history
  • Loading branch information
panic08 authored Oct 14, 2024
1 parent 6c2e3db commit 23bf512
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.gson.JsonParseException;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.text.ParseException;
Expand All @@ -45,15 +46,14 @@ public void write(JsonWriter out, Date date) throws IOException {
@Override
public Date read(JsonReader in) throws IOException {
try {
switch (in.peek()) {
case NULL:
in.nextNull();
return null;
default:
String date = in.nextString();
// Instead of using iso8601Format.parse(value), we use Jackson's date parsing
// This is because Android doesn't support XXX because it is JDK 1.6
return parse(date, new ParsePosition(0));
if (in.peek().equals(JsonToken.NULL)) {
in.nextNull();
return null;
} else {
String date = in.nextString();
// Instead of using iso8601Format.parse(value), we use Jackson's date parsing
// This is because Android doesn't support XXX because it is JDK 1.6
return parse(date, new ParsePosition(0));
}
} catch (ParseException e) {
throw new JsonParseException(e);
Expand Down

0 comments on commit 23bf512

Please sign in to comment.