JSON Serializer

In Versions 7 and above of NServiceBus, the JsonSerializer has been removed. Use the external Json.NET Serializer instead. See also Compatibility between the core and external Json.NET serializer.

Using JSON via an ILMerged copy of Json.NET.



Json.net versions

Over time, the version of ILMerged Json.NET has changed.

NServiceBus VersionJson.net Version
4.1 - 5.X5.0.6


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 via the IgnoreDataMemberAttribute.

The attribute can be used as such

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

    public string FullName { get; set; }

Then when this is serialized.

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

The result 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);



Using BSON via the same ILMerged copy of Json.NET as above.




Last modified