Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问下大佬 Protostuff 如何序列化Class<T> ? #21

Open
Jandaes opened this issue Jan 9, 2018 · 0 comments
Open

请问下大佬 Protostuff 如何序列化Class<T> ? #21

Jandaes opened this issue Jan 9, 2018 · 0 comments

Comments

@Jandaes
Copy link

Jandaes commented Jan 9, 2018

/*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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant