Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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