Created
August 2, 2018 11:16
-
-
Save rishikeshdhokare/1f698184fb1c4076201b9854005bab81 to your computer and use it in GitHub Desktop.
LocalDateDeSerializer
This file contains hidden or 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
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