@Test public void serial() { Bean bean = new Bean("hello world", NUM_18); byte[] bs = SerializationUtil.serial(bean); String hexStr = DataUtil.byte2HexStr(bs); Assert.equals(hexStr, "0A0B68656C6C6F20776F726C641012", ErrorCodeDef.SYSTEM_ERROR_10001); }
@SuppressWarnings("unchecked") public static <T> byte[] serial(final T obj) throws UtilException { if (obj != null && !(obj instanceof Void)) { try { if (obj instanceof Map) { return jdkSerial(obj); } else { Schema<T> schema = RuntimeSchema.getSchema((Class<T>) obj.getClass()); LinkedBuffer buffer = LinkedBuffer.allocate(INIT_SIZE); return ProtostuffIOUtil.toByteArray(obj, schema, buffer); } } catch (Exception e) { throw new UtilException(e, ErrorCodeDef.SERIALIZE_ERROR, obj); } } return null; }
SerializationUtil { @SuppressWarnings("unchecked") public static <T> byte[] serial(final T obj) throws UtilException { if (obj != null && !(obj instanceof Void)) { try { if (obj instanceof Map) { return jdkSerial(obj); } else { Schema<T> schema = RuntimeSchema.getSchema((Class<T>) obj.getClass()); LinkedBuffer buffer = LinkedBuffer.allocate(INIT_SIZE); return ProtostuffIOUtil.toByteArray(obj, schema, buffer); } } catch (Exception e) { throw new UtilException(e, ErrorCodeDef.SERIALIZE_ERROR, obj); } } return null; } }
SerializationUtil { @SuppressWarnings("unchecked") public static <T> byte[] serial(final T obj) throws UtilException { if (obj != null && !(obj instanceof Void)) { try { if (obj instanceof Map) { return jdkSerial(obj); } else { Schema<T> schema = RuntimeSchema.getSchema((Class<T>) obj.getClass()); LinkedBuffer buffer = LinkedBuffer.allocate(INIT_SIZE); return ProtostuffIOUtil.toByteArray(obj, schema, buffer); } } catch (Exception e) { throw new UtilException(e, ErrorCodeDef.SERIALIZE_ERROR, obj); } } return null; }  }
SerializationUtil { @SuppressWarnings("unchecked") public static <T> byte[] serial(final T obj) throws UtilException { if (obj != null && !(obj instanceof Void)) { try { if (obj instanceof Map) { return jdkSerial(obj); } else { Schema<T> schema = RuntimeSchema.getSchema((Class<T>) obj.getClass()); LinkedBuffer buffer = LinkedBuffer.allocate(INIT_SIZE); return ProtostuffIOUtil.toByteArray(obj, schema, buffer); } } catch (Exception e) { throw new UtilException(e, ErrorCodeDef.SERIALIZE_ERROR, obj); } } return null; }  @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> byte[] serial(final T obj) throws UtilException { if (obj != null && !(obj instanceof Void)) { try { if (obj instanceof Map) { return jdkSerial(obj); } else { Schema<T> schema = RuntimeSchema.getSchema((Class<T>) obj.getClass()); LinkedBuffer buffer = LinkedBuffer.allocate(INIT_SIZE); return ProtostuffIOUtil.toByteArray(obj, schema, buffer); } } catch (Exception e) { throw new UtilException(e, ErrorCodeDef.SERIALIZE_ERROR, obj); } } return null; }  @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);  }