<dependency> <groupId>io.protostuff</groupId> <artifactId>protostuff-core</artifactId> <version>1.7.0</version> </dependency> public byte[] serialize(Object obj) throws IOException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); LinkedBuffer buffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE); try { Schema<Object> schema = RuntimeSchema.getSchema(obj.getClass()); ProtostuffIOUtil.writeTo(outputStream, obj, schema, buffer); } finally { buffer.clear(); } return outputStream.toByteArray(); } public Object deserialize(byte[] data, Class<?> clazz) throws IOException { Object obj = null; try { obj = clazz.newInstance(); Schema<Object> schema = RuntimeSchema.getSchema(clazz); ProtostuffIOUtil.mergeFrom(data, obj, schema); e.printStackTrace(); } return obj; }


上一篇:
下一篇:
切换中文