PDA

View Full Version : Make Serializing Type Optional?


LeeRead
05-17-2010, 04:53 PM
Hello,

Because it is tight and lightweight, we often use the Hessian protocol for a mobile phone applications.

We are using the Java version of Hessian - the whole enchilada on the server and MicroHessian on the client. We use Hessian v1 protocol.

Recently I was looking at debug output of Hessian traffic and noticed that types were being transferred. Because we are using MicroHessian on the client we really don't need types (Java class names) to be transferred down to the client. The client just digs through maps and vectors for what it needs, it ignores the type info - so in our case the type info is just wasted bandwidth.

I'm looking at v4.0.6 of Hessian and I see the setSendCollectionType on HessianServlet. Settting this to false helps a bit but Java class names are still being sent back to the client.

Is there an easy way to turn off serializing all Java class type information?

Much Thanks,

-Lee-

emil
05-17-2010, 06:53 PM
Hi Lee,

Which Java types are being sent over? Are they collection types? If so, which ones? Or are they your types?

setSendCollectionType(true) only omits types if a map is a HashMap or a collection is an ArrayList. That's because those are the default types for the Hessian input stream. If you're using other map or collection types, you could add a separate serializer to handle them.

Best,
Emil

LeeRead
05-18-2010, 08:19 PM
Thanks for the reply Emil!

On the server, our Hessian exposed interfaces include parameters and returns that are our own Java classes. When serialized to Hessian, the java objects that are returned over these interfaces automatically become Hessian maps. In a hessian map the type is optional, but by default, the type of a Hessian serialized java object is the java class name.

Our clients, which use MicroHessian, don't make any use of the map type and ignore it - so in this particular use case, it is wasted bandwidth.

For me, it would be kind of cool if there were another HessianServlet option to tell Hessian Serializers to never include the type name when serializing custom Java classes.