@ Override public Date parse ( Object o , Field field ) { if ( ! isValid ( o ) ) { return null ; } JsonFormat formatAnn = field . getAnnotation ( JsonFormat . class ) ; if ( formatAnn == null ) { throw new RuntimeException ( "JsonFormat with pattern needed for: " + field . getName ( ) ) ; } try { return new SimpleDateFormat ( formatAnn . pattern ( ) , Locale . getDefault ( ) ) . parse ( o . toString ( ) ) ; } catch ( ParseException e ) { throw new RuntimeException ( "JsonFormat with pattern is wrong for: " + field . getName ( ) + " pattern: " + formatAnn . pattern ( ) ) ; } }
First it checks is there any annotation class for parsing operations if it is parses with given format if there is a exception while parsing with given format catches and tries with default values If there is no given format tries with static values