Skip to content

Instantly share code, notes, and snippets.

@akleandrov
Created December 27, 2016 06:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akleandrov/e34ca7e9bdbb096863721794e89cc65b to your computer and use it in GitHub Desktop.
Save akleandrov/e34ca7e9bdbb096863721794e89cc65b to your computer and use it in GitHub Desktop.
GSON builder with date format
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