Skip to content

Latest commit

 

History

History
77 lines (49 loc) · 1.59 KB

File metadata and controls

77 lines (49 loc) · 1.59 KB
title summary related
JSON Serializer
A json serializer that uses Json.NET.
samples/serializers/json

Using Json via an ILMerged copy of Json.NET.

Usage

snippet:JsonSerialization

Json.net versions

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

NServiceBus Version Json.net Version
3.X 4.0.8
4.0 4.5.11
4.1-5.X 5.0.6
6.0-6.X 8.0.2

Customization

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; }

    [IgnoreDataMember]
    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

{"FamilyName":"Smith","GivenNames":"John"}

Bson

WARNING: In Version 6 of NServiceBus the built in BSON serializer has been deprecated. The Newtonsoft serializer can be used as a replacement

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

Usage

snippet:BsonSerialization