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 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?