序列化后拷贝流的方式克隆<br>
对象必须实现Serializable接口

@param <T> 对象类型
@param obj 被克隆对象
@return 克隆后的对象
@throws UtilException IO异常和ClassNotFoundException封装
960081
@SuppressWarnings("unchecked")
	public static <T> T cloneByStream(T obj) {
		if (null == obj || false == (obj instanceof Serializable)) {
			return null;
		}
		final FastByteArrayOutputStream byteOut = new FastByteArrayOutputStream();
		ObjectOutputStream out = null;
		try {
			out = new ObjectOutputStream(byteOut);
			out.writeObject(obj);
			out.flush();
			final ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(byteOut.toByteArray()));
			return (T) in.readObject();
		} catch (Exception e) {
			throw new UtilException(e);
		} finally {
			IoUtil.close(out);
		}
	}
825616
@Override
    public String serialize(Object obj) throws JsonMarshallingException {
        try {
            return serializeChecked(obj);
        } catch (Exception e) {
            throw new JsonMarshallingException(e);
        }
    }
1107299
public static String serialize(Object obj) throws SerializationException {
		try {
			if (obj != null) {
				return mapper.writeValueAsString(obj);
			} else {
				return null;
			}
		} catch (Exception e) {
			logger.error("SerializationException {}", e.getMessage());
			throw new SerializationException(e.getMessage());
		}
	}
1186853
static final Object getObjectId(Object obj) {
        if (obj == null) {
            throw new NullPointerException();
        }
        if (!(obj instanceof ZooPC)) {
        	//non-peristent class
        	return null;
        }
        long id = Session.getObjectId(obj);
        //non-persistent object --> null
        return id >= 0 ? id : null;
    }
300916
public static DERUniversalString getInstance(
        Object  obj)
    {
        if (obj == null || obj instanceof DERUniversalString)
        {
            return (DERUniversalString)obj;
        }

        if (obj instanceof ASN1OctetString)
        {
            return new DERUniversalString(((ASN1OctetString)obj).getOctets());
        }

        throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
    }
50720
public static Serializable copy(Serializable obj) {
        try {
            ByteArrayOutputStream buf = new ByteArrayOutputStream(4096);
            ObjectOutputStream out = new ObjectOutputStream(buf);
            out.writeObject(obj);
            out.close();

            ByteArrayInputStream buf2 = new ByteArrayInputStream(buf.toByteArray());
            ObjectInputStream in = new ObjectInputStream(buf2);
            Serializable            obj2 = (Serializable) in.readObject();
            in.close();

            return obj2;
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
470685
private static byte[] serializeObject(Object obj) {

        if (obj == null) {
            return null;
        }

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {
            ObjectOutputStream out = new ObjectOutputStream(baos);
            out.writeObject(obj);
            out.flush();
        } catch (IOException ioex) {
            throw new EJBException("Timer info object failed to serialize.", ioex);
        }

        return baos.toByteArray();
    }
638597
protected ObjectManagerByteArrayOutputStream serialize(java.io.Serializable serializableObject)
                    throws ObjectManagerException
    {
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this,
                        cclass,
                        "serialize",
                        new Object[] { serializableObject });

        ObjectManagerByteArrayOutputStream byteArrayOutputStream = new ObjectManagerByteArrayOutputStream();
        try {
            java.io.ObjectOutputStream objectOutputStream = new java.io.ObjectOutputStream(byteArrayOutputStream);
            objectOutputStream.writeObject(serializableObject);
            objectOutputStream.close();

        } catch (java.io.IOException exception) {
            // No FFDC Code Needed.
            ObjectManager.ffdc.processException(this,
                                                cclass,
                                                "serialize",
                                                exception,
                                                "1:303:1.8");
            if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                trace.exit(this,
                           cclass,
                           "serialize",
                           exception);
            throw new PermanentIOException(this,
                                           exception);
        } // catch.

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this,
                       cclass,
                       "serialize",
                       new Object[] { byteArrayOutputStream });
        return byteArrayOutputStream;
    }
990369
public static String convertSerializableToString(Serializable obj) {
        ByteArrayOutputStream baos = null;
        ObjectOutputStream oos = null;
        try {
            baos = new ByteArrayOutputStream();
            oos = new ObjectOutputStream(baos);
            oos.writeObject(obj);

            return new String(baos.toByteArray());
        } catch (IOException e) {
            return null;
        } finally {
            closeQuietly(baos, oos);
            closeQuietly(oos);
        }
    }
671020
@SuppressWarnings("unchecked")
        public static <T> ClassSup<T> cls(T obj) {
                return mapper.get(obj.getClass().getName(), () -> (ClassSup<T>) cls(obj.getClass()));
        }
1210703
@NonNull
    public static <T> T nonNull(@Nullable T obj) {
        if (obj == null) {
           throw new IllegalArgumentException("encountered illegal null value");
        }
        return obj;
    }
1033405
public static Object serializeAndDeserialize(Object o) throws IOException,
			ClassNotFoundException {
		ByteArrayOutputStream bytes = new ByteArrayOutputStream();
		ObjectOutputStream out = new ObjectOutputStream(bytes);
		try {
			out.writeObject(o);
		} finally {
			out.close();
		}

		ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(
				bytes.toByteArray()));
		try {
			Object result = in.readObject();
			return result;
		} finally {
			in.close();
		}
	}
32535
public static <T extends Object> T getFieldValue(Object obj, String fieldName) {
        Assert.notNull(obj, "obj不能为空");
        Assert.notNull(fieldName, "fieldName不能为空");

        Field field;
        if (obj instanceof Class) {
            field = getField((Class) obj, fieldName);
        } else {
            field = getField(obj.getClass(), fieldName);
        }

        return getFieldValue(obj, field);
    }
622773
public static Class<?> getClass(Object obj) {
		Class<?> cls = obj.getClass();
		return cls != Class.class ? cls : (Class<?>) obj;
	}
336947
public static String convertObjectToString(Object obj)
    {
        try {
            ByteArrayOutputStream writer = new ByteArrayOutputStream();
            ObjectOutputStream outStream = new ObjectOutputStream(writer);
            outStream.writeObject(obj);
            outStream.flush();
            writer.flush();
            String string = writer.toString(Constant.OBJECT_ENCODING);//Constants.STRING_ENCODING);
            writer.close();
            outStream.close();
            return string;
        } catch (IOException ex)    {
            ex.printStackTrace();   // Never
        }
        return null;
    }
870275
public static byte[] toByteArrayFst(final Object obj, final ClassLoader classLoader) {
        if (obj == null) {
            return null;
        }
        ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
        if (classLoader != null) {
            Thread.currentThread().setContextClassLoader(classLoader);
        }
        try {
            FSTConfiguration conf = fstConf.get();
            conf.setClassLoader(classLoader != null ? classLoader : oldClassLoader);
            return conf.asByteArray(obj);
        } catch (Exception e) {
            throw e instanceof SerializationException ? (SerializationException) e
                    : new SerializationException(e);
        } finally {
            Thread.currentThread().setContextClassLoader(oldClassLoader);
        }
    }
11324
public Message setObject(Object obj) {
        if(obj == null) return this;
        if(obj instanceof byte[])
            return setBuffer((byte[])obj);
        if(obj instanceof Buffer)
            return setBuffer((Buffer)obj);
        try {
            return setBuffer(Util.objectToByteBuffer(obj));
        }
        catch(Exception ex) {
            throw new IllegalArgumentException(ex);
        }
    }