@Test public void testDateTimeTimestamp() throws Exception { String dateStr = "2018-09-12"; String timeStr = "10:12:33"; String dateTimeStr = "2018-09-12 10:12:33"; String[] dateFormat = new String[]{"yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd", "HH:mm:ss"}; Object date = PojoUtils.realize(dateTimeStr, Date.class, (Type) Date.class); assertEquals(Date.class, date.getClass()); assertEquals(dateTimeStr, new SimpleDateFormat(dateFormat[0]).format(date)); Object time = PojoUtils.realize(dateTimeStr, java.sql.Time.class, (Type) java.sql.Time.class); assertEquals(java.sql.Time.class, time.getClass()); assertEquals(timeStr, new SimpleDateFormat(dateFormat[2]).format(time)); Object sqlDate = PojoUtils.realize(dateTimeStr, java.sql.Date.class, (Type) java.sql.Date.class); assertEquals(java.sql.Date.class, sqlDate.getClass()); assertEquals(dateStr, new SimpleDateFormat(dateFormat[1]).format(sqlDate)); Object timestamp = PojoUtils.realize(dateTimeStr, java.sql.Timestamp.class, (Type) java.sql.Timestamp.class); assertEquals(java.sql.Timestamp.class, timestamp.getClass()); assertEquals(dateTimeStr, new SimpleDateFormat(dateFormat[0]).format(timestamp)); }
public static Object[] realize(Object[] objs, Class<?>[] types) { if (objs.length != types.length) throw new IllegalArgumentException("args.length != types.length"); Object[] dests = new Object[objs.length]; for (int i = 0; i < objs.length; i++) { dests[i] = realize(objs[i], types[i]); } return dests; }
PojoUtils { public static Object[] realize(Object[] objs, Class<?>[] types) { if (objs.length != types.length) throw new IllegalArgumentException("args.length != types.length"); Object[] dests = new Object[objs.length]; for (int i = 0; i < objs.length; i++) { dests[i] = realize(objs[i], types[i]); } return dests; } }
PojoUtils { public static Object[] realize(Object[] objs, Class<?>[] types) { if (objs.length != types.length) throw new IllegalArgumentException("args.length != types.length"); Object[] dests = new Object[objs.length]; for (int i = 0; i < objs.length; i++) { dests[i] = realize(objs[i], types[i]); } return dests; }  }
PojoUtils { public static Object[] realize(Object[] objs, Class<?>[] types) { if (objs.length != types.length) throw new IllegalArgumentException("args.length != types.length"); Object[] dests = new Object[objs.length]; for (int i = 0; i < objs.length; i++) { dests[i] = realize(objs[i], types[i]); } return dests; }  static Object[] generalize(Object[] objs); static Object[] realize(Object[] objs, Class<?>[] types); static Object[] realize(Object[] objs, Class<?>[] types, Type[] gtypes); static Object generalize(Object pojo); static Object realize(Object pojo, Class<?> type); static Object realize(Object pojo, Class<?> type, Type genericType); static boolean isPojo(Class<?> cls); }
PojoUtils { public static Object[] realize(Object[] objs, Class<?>[] types) { if (objs.length != types.length) throw new IllegalArgumentException("args.length != types.length"); Object[] dests = new Object[objs.length]; for (int i = 0; i < objs.length; i++) { dests[i] = realize(objs[i], types[i]); } return dests; }  static Object[] generalize(Object[] objs); static Object[] realize(Object[] objs, Class<?>[] types); static Object[] realize(Object[] objs, Class<?>[] types, Type[] gtypes); static Object generalize(Object pojo); static Object realize(Object pojo, Class<?> type); static Object realize(Object pojo, Class<?> type, Type genericType); static boolean isPojo(Class<?> cls);  }