我正在尝试使用他们的wiki的示例序列化POJO,但我得到“协议消息包含无效标记(零)。”我希望我的POJO转换为byte [],将其发送到消息代理,检索它并反序列化它。我有一个单元测试来测试它,它似乎工作,但当我通过经纪人,它打破了。这是我的代码:
private final Schema<MyObject> schema = RuntimeSchema.getSchema(MyObject.class);
private final LinkedBuffer buffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE);
//Serialization
byte[] result = ProtostuffIOUtil.toByteArray(myObject, schema, buffer);
// Send result to message broker
// Receive result from message broker
//Deserialization
MyObject myObject = schema.newInstance();
ProtostuffIOUtil.mergeFrom(b, myObject, schema); <--- Exception thrown
堆栈跟踪是:
Caused by: java.lang.RuntimeException: Reading from a byte array threw an IOException (should never happen).
at com.dyuproject.protostuff.IOUtil.mergeFrom(IOUtil.java:53) ~[protostuff-core-1.0.7.jar:1.0.7]
at com.dyuproject.protostuff.ProtostuffIOUtil.mergeFrom(ProtostuffIOUtil.java:96) ~[protostuff-core-1.0.7.jar:1.0.7]
... 19 more
Caused by: com.dyuproject.protostuff.ProtobufException: Protocol message contained an invalid tag (zero).
at com.dyuproject.protostuff.ProtobufException.invalidTag(ProtobufException.java:98) ~[protostuff-core-1.0.7.jar:1.0.7]
at com.dyuproject.protostuff.ByteArrayInput.readFieldNumber(ByteArrayInput.java:220) ~[protostuff-core-1.0.7.jar:1.0.7]
at com.dyuproject.protostuff.runtime.MappedSchema.mergeFrom(MappedSchema.java:179) ~[protostuff-runtime-1.0.7.jar:1.0.7]
at com.dyuproject.protostuff.IOUtil.mergeFrom(IOUtil.java:43) ~[protostuff-core-1.0.7.jar:1.0.7]
at com.dyuproject.protostuff.ProtostuffIOUtil.mergeFrom(ProtostuffIOUtil.java:96) ~[protostuff-core-1.0.7.jar:1.0.7]...
知道我做错了什么吗?谢谢!