开发者

What is the best way to interoperably serialize a message?

I'm considering message serialization support for spring-integration. This would be useful for various wire level transports to implement guaranteed delivery, but also to allow interoperability with other messaging systems (e.g. through开发者_Go百科 AMQP).

The fundamental problem that arises is that a message containing Java object in it's payload and headers should be converted to a byte[] and/or written to a stream. Java's own serialization is clearly not going to cut it because that is not interoperable. My preference would be to create an interface that allows the user to implement the needed logic for all Objects that take part in serialization.

This means I don't want to require the client developer to generate his domain code, but rather define a serializer for objects that need it. The interfaces would be something like:

public interface PayloadSerializer<T> {
    byte[] bytesForObject(T source);
    T objectFromBytes(byte[]);
    //similar methods for streaming potentially
}

//add HeaderSerializer, MessageSerializer

Is this a sensible idea and what would the perfect interface look like? Is there a standard interoperable way to serialize Objects that would make sense in this context?


There is a whole set of frameworks in java which generate XML, like JaxB, ... Now some of these formats might just as well be binary blobs and are difficult to use from other platforms, so it pays to try before you buy. There are also very easy to use XML serializers.

JSON is very popular nowadays because it gives easy interop with the browser and it is readable ad less verbose than XML.

Protocol Buffers and Thrift are popular when performance is important. These are binary formats but well specified and well supported on multiple platforms.


I would try to serialize the java objects into a XML representation and convert this into a byte array for stream I/O.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜