Question

I have a Java Server that sending the java serializable object to my client, and receive java serializable object for execution. If my client is also java written, which is nice, that allow me to do communication within any problems.

But now, I would like to extend my programme to not only java client, the client may be written in C, objective C, python or php. So, I would like to do something to "convent" to client request to a java object, and send back to Server. The convent process, I can use the JSON to receive, and construct a Java object to the Server, but I also need a layer that convert back the Java object to JSON to the client.

My Question is except make a JSON-Java Translation layer, is there any other ways to do so? Also, we can afford to change some code in server side, but we must use Java as our primary language for that. Any suggestions? Thanks.

Was it helpful?

Solution

I use Netty API for designing my protocol and it is quite quick to do so if you can understand a NIO-like Byte and Buffer API. It is design to work with a concept of Encoder and Decoder that could fit your need, there are a lot of default implementation of Encoder and Decoder for zipping, using ssl...

The problem you have seems to looks like this one: JBoss Netty with JSON

I don't know JSON very well but most of the time is could also be quick and easy to design your own protocol.

Do you need a generic Serialization process for any kind of Object or do you simply need to serialize some String and primitive types (Integer, Short, Float..etc)? In the case of simple objects it is easy and a lot faster to do the wrapper by yourself.

If objects are quite simple, and I would guess this is the case, your need it to design your own "protocol" specification meaning how to turn each Object into a sequence of primitive types, String and arrays. Than it should be quite easy to write both the Encoder and the Decoder in each language.

Good luck

OTHER TIPS

There are other libraries designed for this, like protocol buffers and thrift.

http://thrift.apache.org/

http://code.google.com/p/protobuf/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top