Skip to content

Instantly share code, notes, and snippets.

@rishikeshdhokare
Created August 2, 2018 11:16
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 rishikeshdhokare/1f698184fb1c4076201b9854005bab81 to your computer and use it in GitHub Desktop.
Save rishikeshdhokare/1f698184fb1c4076201b9854005bab81 to your computer and use it in GitHub Desktop.
LocalDateDeSerializer
public class LocalDateDeSerializer extends StdDeserializer<LocalDate> {
public LocalDateDeSerializer() {
this(null);
}
public LocalDateDeSerializer(Class<?> vc) {
super(vc);
}
@Override
public LocalDate deserialize(JsonParser jsonParser, DeserializationContext context) throws JsonParseException{
try {
String date = jsonParser.getText();
return LocalDate.parse(date, DateTimeFormatter.ISO_DATE);
}catch (Exception ex){
throw new WebApplicationException("Invalid date format, expected format is ISO Date format. Ex. yyyy-MM-dd");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment