Skip to content
This repository has been archived by the owner on Nov 26, 2022. It is now read-only.

Commit

Permalink
Allow GSON parse Date from blank string and null
Browse files Browse the repository at this point in the history
  • Loading branch information
Decky Fiyemonda committed Nov 23, 2018
1 parent a25dce0 commit 0b11af8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
15 changes: 13 additions & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-rc02'
classpath 'com.android.tools.build:gradle:3.3.0-alpha08'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Additional libraries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public class DateTimeSerializer implements JsonDeserializer<Date>, JsonSerialize
"yyyy-MM-dd HH:mm:ss",
"yyyy-MM-dd",
"HH:mm:ss",
"timestamp"
"timestamp",
"blank",
"null"
};

@Override
Expand All @@ -35,6 +37,20 @@ public Date deserialize(JsonElement jsonElement, Type typeOF, JsonDeserializatio
return new Date(jsonElement.getAsLong());
} catch (Exception e) {
}
} else if (format.equalsIgnoreCase("null")) {
try {
if (jsonElement.getAsString() == null) {
return null;
}
} catch (Exception e) {
}
} else if (format.equalsIgnoreCase("blank")) {
try {
if (jsonElement.getAsString().length() == 0) {
return null;
}
} catch (Exception e) {
}
} else {
try {
return new SimpleDateFormat(format, Locale.US).parse(jsonElement.getAsString());
Expand Down

0 comments on commit 0b11af8

Please sign in to comment.