@Test public void unserial() { byte[] bs = DataUtil.hexStr2Byte("0A0B68656C6C6F20776F726C641012"); Bean bean = SerializationUtil.unserial(Bean.class, bs); Assert.equals(bean.getName(), "hello world", ErrorCodeDef.SYSTEM_ERROR_10001); }
@SuppressWarnings("unchecked") public static <T> T unserial(final Class<T> clazz, final byte[] data) throws UtilException { T result = null; if (data != null && data.length > 0) { try { if (Map.class.isAssignableFrom(clazz)) { result = (T) jdkUnserial(data); } else { Schema<T> schema = RuntimeSchema.getSchema(clazz); result = clazz.newInstance(); ProtostuffIOUtil.mergeFrom(data, result, schema); } } catch (Exception e) { throw new UtilException(e, ErrorCodeDef.UNSERIALIZE_ERROR, DataUtil.byte2HexStr(data)); } } return result; }
SerializationUtil { @SuppressWarnings("unchecked") public static <T> T unserial(final Class<T> clazz, final byte[] data) throws UtilException { T result = null; if (data != null && data.length > 0) { try { if (Map.class.isAssignableFrom(clazz)) { result = (T) jdkUnserial(data); } else { Schema<T> schema = RuntimeSchema.getSchema(clazz); result = clazz.newInstance(); ProtostuffIOUtil.mergeFrom(data, result, schema); } } catch (Exception e) { throw new UtilException(e, ErrorCodeDef.UNSERIALIZE_ERROR, DataUtil.byte2HexStr(data)); } } return result; } }
SerializationUtil { @SuppressWarnings("unchecked") public static <T> T unserial(final Class<T> clazz, final byte[] data) throws UtilException { T result = null; if (data != null && data.length > 0) { try { if (Map.class.isAssignableFrom(clazz)) { result = (T) jdkUnserial(data); } else { Schema<T> schema = RuntimeSchema.getSchema(clazz); result = clazz.newInstance(); ProtostuffIOUtil.mergeFrom(data, result, schema); } } catch (Exception e) { throw new UtilException(e, ErrorCodeDef.UNSERIALIZE_ERROR, DataUtil.byte2HexStr(data)); } } return result; }  }
SerializationUtil { @SuppressWarnings("unchecked") public static <T> T unserial(final Class<T> clazz, final byte[] data) throws UtilException { T result = null; if (data != null && data.length > 0) { try { if (Map.class.isAssignableFrom(clazz)) { result = (T) jdkUnserial(data); } else { Schema<T> schema = RuntimeSchema.getSchema(clazz); result = clazz.newInstance(); ProtostuffIOUtil.mergeFrom(data, result, schema); } } catch (Exception e) { throw new UtilException(e, ErrorCodeDef.UNSERIALIZE_ERROR, DataUtil.byte2HexStr(data)); } } return result; }  @SuppressWarnings("unchecked") static byte[] serial(final T obj); static byte[] jdkSerial(final Object obj); @SuppressWarnings("unchecked") static T unserial(final Class<T> clazz, final byte[] data); static Object jdkUnserial(final byte[] data); }
SerializationUtil { @SuppressWarnings("unchecked") public static <T> T unserial(final Class<T> clazz, final byte[] data) throws UtilException { T result = null; if (data != null && data.length > 0) { try { if (Map.class.isAssignableFrom(clazz)) { result = (T) jdkUnserial(data); } else { Schema<T> schema = RuntimeSchema.getSchema(clazz); result = clazz.newInstance(); ProtostuffIOUtil.mergeFrom(data, result, schema); } } catch (Exception e) { throw new UtilException(e, ErrorCodeDef.UNSERIALIZE_ERROR, DataUtil.byte2HexStr(data)); } } return result; }  @SuppressWarnings("unchecked") static byte[] serial(final T obj); static byte[] jdkSerial(final Object obj); @SuppressWarnings("unchecked") static T unserial(final Class<T> clazz, final byte[] data); static Object jdkUnserial(final byte[] data);  }