DateTimeCodec implements ValueCodec { @Override @SuppressWarnings("all") public Object decode(Object data) { if (null == data) { return null; } if (toType.isAssignableFrom(data.getClass())) { return data; } if (data instanceof Number) { data = new Date(((Number) data).longValue()); } else if (data instanceof Timestamp) { data = Date.from(((Timestamp) data).toInstant()); } else if (data instanceof Instant) { data = Date.from(((Instant) data)); } else if (data instanceof LocalDateTime) { LocalDateTime dateTime = ((LocalDateTime) data); data = Date.from(dateTime.atZone(ZoneOffset.systemDefault()).toInstant()); } if (data instanceof Date) { if (toType == Date.class) { return data; } if (toType == String.class) { return DateTimeUtils.format(((Date) data), format); } } if (data instanceof Collection) { return ((Collection<?>) data) .stream() .map(this::decode) .collect((Collector) (toType == String.class ? Collectors.joining(",") : Collectors.toList())); } if (data instanceof String) { String stringData = ((String) data); if (toType == Date.class) { if ((stringData).contains(",")) { return Arrays.stream(stringData.split(",")) .map(this::doParse) .filter(Objects::nonNull) .collect(Collectors.toList()); } data = this.doParse(stringData); } } return data; } DateTimeCodec(String format, Class toType); @Override Object encode(Object value); @Override @SuppressWarnings("all") Object decode(Object data);  }
@Test public void testDeCodeList() { DateTimeCodec codec = new DateTimeCodec("yyyy-MM-dd", Date.class); String str = "2019-01-01,2019-01-31"; Object encode = codec.decode(str); Assert.assertTrue(encode instanceof List); Assert.assertArrayEquals(((List) encode).toArray(), Arrays.stream(str.split("[,]")).map(codec::encode).toArray()); }