JSON Serializer

NuGet Package: NServiceBus (6.x)
Standard support for version 6.x of NServiceBus has expired. For more information see our Support Policy.
In NServiceBus version 7 and above, the JsonSerializer has been removed. Use the external Json.NET Serializer instead. See also Compatibility between the core and external Json.NET serializer.

This serializer uses JSON via an ILMerged copy of Json.NET.



Json.NET version

Version 8.0.2 of Json.NET is ILMerged.

By default, the Json.NET serializer adds a Byte Order Mark (BOM). To disable this, see the customizing encoding section.


Since Json.NET is ILMerged, the Json.NET customization attributes are not supported. However, certain customizations are still supported via standard .NET attributes.

Excluding members

Members can be exclude using the IgnoreDataMemberAttribute.

The attribute can be used as follows:

public class Person
    public string FamilyName { get; set; }
    public string GivenNames { get; set; }

    public string FullName { get; set; }

The serialized output for following instance:

Person person = new Person
    GivenNames = "John",
    FamilyName = "Smith",
    FullName = "John Smith"

will be:


Customizing encoding

By default, the JSON serializer uses UTF8 encoding. To customize the encoding, use the following API. In the example below, the custom encoding omits the Byte Order Mark (BOM).

var noBomEncoding = new UTF8Encoding(false, false);


Inferring message type from $type

For integration scenarios where the sender is unable to add message headers, the serializer is able to infer the message type from the $type property supported by Json.NET. By default Json.NET requires the property to contain the assembly-qualified name of the message type but to make integration easier, the serializer also registers a custom binder that allows only the full type name to be passed.

See the native integration with SqlTransport sample for more details.


The built in BSON serializer has been deprecated. The external Newtonsoft serializer can be used as a replacement.


Last modified