List serialization/deserialization

702 views
Skip to first unread message

xavan

unread,
Jul 26, 2011, 11:54:50 AM7/26/11
to protostuff
I try to implements Rest services using protostuff as protocol.
I want to code a generic serializer/deserializer (also able to use
List).
It works well for the following bean:
// BaseModel contains only one identifier and a java.util.Date
public class User extends BaseModel{

private String email;

private String userName;

private String password;

The writer look like this:
...
List<Object> c = (List<Object>) t;
Schema<Object> schema =
RuntimeSchema.getSchema(c.get(0) .getClass().getName(), true);
ProtostuffIOUtil.writeListTo(entityStream, c, schema,buffer);

and a finally to clear the buffer:
buffer.clear();

The reader:
// First I retrieve the generic type of the list
Class<?> baseType = Types.getCollectionBaseType(type, genericType);
Schema<?> schema = RuntimeSchema.getSchema(baseType);
List<?> result = ProtobufIOUtil.parseListFrom(entityStream, schema);

The client receive the following data (log4j log, mix of text and hexa
data) for a list of 3users:
DEBUG httpclient - << "[0x3][0x8][0x9b][0x8][0x11]9m[0xe9]f1[0x1][0x0]
[0x0]"[0x4]test*[0x4]test2[0x4]test[0x7][0x8][0x95][\n]"
DEBUG httpclient - << "[0x11][0x1a]A[0xb]g1[0x1][0x0]
[0x0]"[0x4]test*[0x4]test2[0x4]test[0x7][0x8][0x96][\n]"
DEBUG httpclient - << "[0x11][0xab][0xca][0xb]g1[0x1][0x0]
[0x0]"[0x4]test*[0x4]test2[0x4]test[0x7]"

However the deserialization process throw the following error:
Exception in thread "main" org.jboss.resteasy.spi.ReaderException:
com.dyuproject.protostuff.ProtobufException: Protocol message
contained an invalid tag (zero).
at
org.jboss.resteasy.client.core.BaseClientResponse.readFrom(BaseClientResponse.java:
434)
at
org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:
346)
at
org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:
319)
at
org.jboss.resteasy.client.core.extractors.BodyEntityExtractor.extractEntity(BodyEntityExtractor.java:
56)
at
org.jboss.resteasy.client.core.ClientInvoker.invoke(ClientInvoker.java:
115)
at org.jboss.resteasy.client.core.ClientProxy.invoke(ClientProxy.java:
72)
at $Proxy22.findAll(Unknown Source)
at com.ep.testjersey.client.UserClient.main(UserClient.java:37)
Caused by: com.dyuproject.protostuff.ProtobufException: Protocol
message contained an invalid tag (zero).
at
com.dyuproject.protostuff.ProtobufException.invalidTag(ProtobufException.java:
98)
at
com.dyuproject.protostuff.ByteArrayInput.readFieldNumber(ByteArrayInput.java:
220)
at
com.dyuproject.protostuff.runtime.MappedSchema.mergeFrom(MappedSchema.java:
180)
at
com.dyuproject.protostuff.ProtobufIOUtil.parseListFrom(ProtobufIOUtil.java:
343)
at
com.ep.testjersey.converter.ProtoStuffReader.readFrom(ProtoStuffReader.java:
61)
at
org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl.proceed(MessageBodyReaderContextImpl.java:
105)
at
org.jboss.resteasy.security.signing.DigitalVerificationInterceptor.read(DigitalVerificationInterceptor.java:
35)
at
org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl.proceed(MessageBodyReaderContextImpl.java:
108)
at
org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.read(GZIPDecodingInterceptor.java:
46)
at
org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl.proceed(MessageBodyReaderContextImpl.java:
108)
at
org.jboss.resteasy.client.core.BaseClientResponse.readFrom(BaseClientResponse.java:
398)
... 7 more


David Yu

unread,
Jul 26, 2011, 9:34:18 PM7/26/11
to proto...@googlegroups.com
Your serializer did not match your deserializer.
Since your'e using ProtostuffIOUtil to serialize, do not use ProtobufIOUtil.parseListFrom(entityStream, schema);
Use ProtostuffIOUtil.parseListFrom(entityStream, schema); // this is also very efficient since we're streaming data.
--
When the cat is away, the mouse is alone.
- David Yu
Reply all
Reply to author
Forward
0 new messages