NServiceBus takes instances of .NET objects (messages, events, and commands) and sends/receives them over a specified transport. As part of this process, the object must be serialized and deserialized. NServiceBus achieves this using serializers.
It's possible to transition to another serialization format while still remaining compatible with messages in-flight that used the previous serialization format. This is accomplished by adding the previous serialization format as an additional deserializer, which is supported in NServiceBus versions 6 and above.
The Newtonsoft JSON Serializer provides an effective general-purpose serializer appropriate for most use cases based on the ubiquitous Json.NET package. The Newtonsoft package provides a good combination of compactness, human readability, and performance. Other serializers are supported in order to enable specific performance or integration requirements.
- JSON/BSON (deprecated in NServiceBus versions 7 and above)
- Binary (deprecated in NServiceBus versions 6 and above)
The default serializer used in NServiceBus projects is the custom XmlSerializer.
The pages dedicated to particular serializers show how to configure the endpoint to use each of them. Unless explicitly configured otherwise, NServiceBus will use XmlSerializer for serializing and deserializing all messages.
In order to register a community-maintained serializer or custom serializer, refer to the Custom serializers - Register the serializer section.
To support sending and receiving messages between endpoints using different serializers, additional deserialization capability may be specified. It is possible to register additional deserializers to process incoming messages. Additionally, if a deserializer requires custom settings, they can be provided during its registration.
// Configures new default serialization var mySerializer = endpointConfiguration.UseSerialization<MyCustomSerializerDefinition>(); mySerializer.Settings("serializerSetting"); // Configures additional deserializer, like the previous (default) serializer to be compatible with in-flight messages. endpointConfiguration.AddDeserializer<XmlSerializer>();