Search code examples
c#javaserializationazureservicebus

Azure Service Bus Serialization Issues [C# / JAVA]


I have some problems with serialization in c# and java cross platform:

We have 2 apps using ServiceBus, a C# one and a JAVA one. Lets say C# is in charge of publishing data to a queue / topic and JAVA is subscribing to it.

In C# we use the standard publish method which allows generic types publish so it automatically serializes data sent with TypeA class.

Then in java we have TypeA equivalent coded, but cannot find any API-Deserializer that can deserialize the object to our .

Is there any valid deserializer for JAVA or we must serialize (for example using JSON) in C#, publish it and deserialize in JAVA with any JSON deserializer?

Thanks in advance!


Solution

  • I believe one of the DataContractSerializers will be used if you don't do anything on the BrokeredMessage. You didn't show any code, but I assume you are using BrokeredMessage class. If you want cross-platform, you need to control the serialization. I would serialize to JSON and either pass the JSON as a string, or use the stream overload and perhaps compress the stream, passing that in the constructor (if it was a big object). The Java client would need to get a JSON deserializer and do the reverse.

    As you have figured out - the DataContractSerializer is not easily reversible in Java. I am sure you could do it, but using JSON or protobuf is a way easier and cross platform way.