@Test public void shouldConvertLongToDate() throws IOException { Date date = new Date(); when(jsonParser.getText()).thenReturn(String.valueOf(date.getTime())); Date deSerializedDate = dateDeserializer.deserialize(jsonParser, deserializationContext); assertThat(deSerializedDate.getTime(), is(date.getTime())); }
@Override public Date deserialize(JsonParser jsonparser, DeserializationContext deserializationcontext) throws IOException { try { if(isBlank(jsonparser.getText())) return null; return new Date(Long.parseLong(jsonparser.getText())); } catch (NumberFormatException e) { try { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setTimeZone(TimeZone.getDefault()); return dateFormat.parse(jsonparser.getText()); } catch (ParseException ex) { throw new RuntimeException(ex); } } }
DateDeserializer extends JsonDeserializer<Date> { @Override public Date deserialize(JsonParser jsonparser, DeserializationContext deserializationcontext) throws IOException { try { if(isBlank(jsonparser.getText())) return null; return new Date(Long.parseLong(jsonparser.getText())); } catch (NumberFormatException e) { try { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setTimeZone(TimeZone.getDefault()); return dateFormat.parse(jsonparser.getText()); } catch (ParseException ex) { throw new RuntimeException(ex); } } } }
DateDeserializer extends JsonDeserializer<Date> { @Override public Date deserialize(JsonParser jsonparser, DeserializationContext deserializationcontext) throws IOException { try { if(isBlank(jsonparser.getText())) return null; return new Date(Long.parseLong(jsonparser.getText())); } catch (NumberFormatException e) { try { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setTimeZone(TimeZone.getDefault()); return dateFormat.parse(jsonparser.getText()); } catch (ParseException ex) { throw new RuntimeException(ex); } } }  }
DateDeserializer extends JsonDeserializer<Date> { @Override public Date deserialize(JsonParser jsonparser, DeserializationContext deserializationcontext) throws IOException { try { if(isBlank(jsonparser.getText())) return null; return new Date(Long.parseLong(jsonparser.getText())); } catch (NumberFormatException e) { try { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setTimeZone(TimeZone.getDefault()); return dateFormat.parse(jsonparser.getText()); } catch (ParseException ex) { throw new RuntimeException(ex); } } }  @Override Date deserialize(JsonParser jsonparser,
                          DeserializationContext deserializationcontext); }
DateDeserializer extends JsonDeserializer<Date> { @Override public Date deserialize(JsonParser jsonparser, DeserializationContext deserializationcontext) throws IOException { try { if(isBlank(jsonparser.getText())) return null; return new Date(Long.parseLong(jsonparser.getText())); } catch (NumberFormatException e) { try { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setTimeZone(TimeZone.getDefault()); return dateFormat.parse(jsonparser.getText()); } catch (ParseException ex) { throw new RuntimeException(ex); } } }  @Override Date deserialize(JsonParser jsonparser,
                          DeserializationContext deserializationcontext);  }