Created
December 27, 2016 06:05
-
-
Save akleandrov/e34ca7e9bdbb096863721794e89cc65b to your computer and use it in GitHub Desktop.
GSON builder with date format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GsonBuilder builder = new GsonBuilder(); | |
builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() { | |
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm"); | |
@Override | |
public Date deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) | |
throws JsonParseException { | |
try { | |
return df.parse(json.getAsString()); | |
} catch (ParseException e) { | |
return null; | |
} | |
} | |
}); | |
try | |
{ | |
Gson gson = builder.create(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment