From 34125ee2745262d0116ddf50130693c07e7a9159 Mon Sep 17 00:00:00 2001 From: thinkgem Date: Mon, 24 Sep 2018 11:46:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=9B=E5=9E=8B=E5=8C=96=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E5=BA=8F=E5=88=97=E5=8C=96=E5=92=8C=E5=8F=8D=E5=BA=8F=E5=88=97?= =?UTF-8?q?=E5=8C=96=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/jeesite/common/lang/ObjectUtils.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/common/src/main/java/com/jeesite/common/lang/ObjectUtils.java b/common/src/main/java/com/jeesite/common/lang/ObjectUtils.java index 657d10bf..2d370ed3 100644 --- a/common/src/main/java/com/jeesite/common/lang/ObjectUtils.java +++ b/common/src/main/java/com/jeesite/common/lang/ObjectUtils.java @@ -158,7 +158,7 @@ public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils { * @param object * @return */ - public static byte[] serialize(Object object) { + public static byte[] serialize(T object) { if (object == null){ return null; } @@ -183,16 +183,17 @@ public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils { * @param bytes * @return */ - public static Object unserialize(byte[] bytes) { + @SuppressWarnings("unchecked") + public static T unserialize(byte[] bytes) { if (bytes == null){ return null; } long beginTime = System.currentTimeMillis(); - Object object = null; + T object = null; if (bytes.length > 0) { try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bais);) { - object = ois.readObject(); + object = (T)ois.readObject(); } catch (Exception e) { e.printStackTrace(); } @@ -216,7 +217,7 @@ public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils { * @param object * @return */ - public static byte[] serializeFst(Object object) { + public static byte[] serializeFst(T object) { if (object == null){ return null; } @@ -234,12 +235,13 @@ public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils { * @param bytes * @return */ - public static Object unserializeFst(byte[] bytes) { + @SuppressWarnings("unchecked") + public static T unserializeFst(byte[] bytes) { if (bytes == null){ return null; } long beginTime = System.currentTimeMillis(); - Object object = fst.get().asObject(bytes); + T object = (T)fst.get().asObject(bytes); long totalTime = System.currentTimeMillis() - beginTime; if (totalTime > 3000){ System.out.println("Fst unserialize time: " + TimeUtils.formatDateAgo(totalTime)); @@ -251,12 +253,12 @@ public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils { * 克隆一个对象(完全拷贝) * @param source */ - public static Object cloneBean(Object source){ + public static T cloneBean(T source){ if (source == null){ return null; } byte[] bytes = ObjectUtils.serializeFst(source); - Object target = ObjectUtils.unserializeFst(bytes); + T target = ObjectUtils.unserializeFst(bytes); return target; }