Protostuff 如何序列化Class?
/*Protostuff 序列化泛型类*/
Page<User> pageUser = new Page<User>();
private RuntimeSchema<Item> schema = RuntimeSchema.createFrom(pageUser .class);//这里就不行了
byte[] array=ProtostuffIOUtil.toByteArray(item,schema,
LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE));
/*Protostuff 无法序列化泛型类*/
System.out.println("序列化数据为"+array);
/*异常信息*/
Exception in thread "main" java.lang.RuntimeException: Reading from a byte array threw an IOException (should never happen).
at com.dyuproject.protostuff.IOUtil.mergeFrom(IOUtil.java:52)
at com.dyuproject.protostuff.ProtobufIOUtil.mergeFrom(ProtobufIOUtil.java:95)
at com.cityline.shoe.common.utils.SerializationUtils.main(SerializationUtils.java:44)
Caused by: com.dyuproject.protostuff.ProtostuffException: Corrupt input.
at com.dyuproject.protostuff.runtime.ObjectSchema.readObjectFrom(ObjectSchema.java:641)
at com.dyuproject.protostuff.runtime.ObjectSchema.mergeFrom(ObjectSchema.java:312)
at com.dyuproject.protostuff.ByteArrayInput.mergeObject(ByteArrayInput.java:375)
at com.dyuproject.protostuff.runtime.RuntimeRepeatedFieldFactory$5.mergeFrom(RuntimeRepeatedFieldFactory.java:385)
at com.dyuproject.protostuff.runtime.MappedSchema.mergeFrom(MappedSchema.java:196)
at com.dyuproject.protostuff.IOUtil.mergeFrom(IOUtil.java:43)
... 2 more
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论