@Test public void getLocalDateConverter() throws Exception { JavaTimeParamConverterProvider provider = new JavaTimeParamConverterProvider(); ParamConverter<LocalDate> converter = provider.getConverter(LocalDate.class, null, null); assertNull(converter.fromString(null)); assertEquals(LocalDate.of(2017, 5, 12), converter.fromString("2017-05-12")); assertEquals("2017-05-12", converter.toString(LocalDate.of(2017, 5, 12))); }
@Override public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) { if (rawType.equals(LocalDate.class)) { return new ParamConverter<T>() { @Override public T fromString(String s) { if (s == null) { return null; } return rawType.cast(LocalDate.parse(s)); } @Override public String toString(T t) { return t.toString(); } }; } else if (rawType.equals(Instant.class)) { return new ParamConverter<T>() { @Override public T fromString(String s) { if (s == null) { return null; } try { return rawType.cast(Instant.ofEpochMilli(Long.parseLong(s))); } catch (NumberFormatException e) { return rawType.cast(Instant.parse(s)); } } @Override public String toString(T t) { return t.toString(); } }; } return null; }
JavaTimeParamConverterProvider implements ParamConverterProvider { @Override public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) { if (rawType.equals(LocalDate.class)) { return new ParamConverter<T>() { @Override public T fromString(String s) { if (s == null) { return null; } return rawType.cast(LocalDate.parse(s)); } @Override public String toString(T t) { return t.toString(); } }; } else if (rawType.equals(Instant.class)) { return new ParamConverter<T>() { @Override public T fromString(String s) { if (s == null) { return null; } try { return rawType.cast(Instant.ofEpochMilli(Long.parseLong(s))); } catch (NumberFormatException e) { return rawType.cast(Instant.parse(s)); } } @Override public String toString(T t) { return t.toString(); } }; } return null; } }
JavaTimeParamConverterProvider implements ParamConverterProvider { @Override public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) { if (rawType.equals(LocalDate.class)) { return new ParamConverter<T>() { @Override public T fromString(String s) { if (s == null) { return null; } return rawType.cast(LocalDate.parse(s)); } @Override public String toString(T t) { return t.toString(); } }; } else if (rawType.equals(Instant.class)) { return new ParamConverter<T>() { @Override public T fromString(String s) { if (s == null) { return null; } try { return rawType.cast(Instant.ofEpochMilli(Long.parseLong(s))); } catch (NumberFormatException e) { return rawType.cast(Instant.parse(s)); } } @Override public String toString(T t) { return t.toString(); } }; } return null; }  }
JavaTimeParamConverterProvider implements ParamConverterProvider { @Override public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) { if (rawType.equals(LocalDate.class)) { return new ParamConverter<T>() { @Override public T fromString(String s) { if (s == null) { return null; } return rawType.cast(LocalDate.parse(s)); } @Override public String toString(T t) { return t.toString(); } }; } else if (rawType.equals(Instant.class)) { return new ParamConverter<T>() { @Override public T fromString(String s) { if (s == null) { return null; } try { return rawType.cast(Instant.ofEpochMilli(Long.parseLong(s))); } catch (NumberFormatException e) { return rawType.cast(Instant.parse(s)); } } @Override public String toString(T t) { return t.toString(); } }; } return null; }  @Override ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations); }
JavaTimeParamConverterProvider implements ParamConverterProvider { @Override public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) { if (rawType.equals(LocalDate.class)) { return new ParamConverter<T>() { @Override public T fromString(String s) { if (s == null) { return null; } return rawType.cast(LocalDate.parse(s)); } @Override public String toString(T t) { return t.toString(); } }; } else if (rawType.equals(Instant.class)) { return new ParamConverter<T>() { @Override public T fromString(String s) { if (s == null) { return null; } try { return rawType.cast(Instant.ofEpochMilli(Long.parseLong(s))); } catch (NumberFormatException e) { return rawType.cast(Instant.parse(s)); } } @Override public String toString(T t) { return t.toString(); } }; } return null; }  @Override ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations);  }