JSON Serializer

Using Json via an ILMerged copy of Json.NET.

Usage

endpointConfiguration.UseSerialization<JsonSerializer>();

Json.net version

Version 8.0.2 of Json.Net is ILMerged.

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

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

endpointConfiguration.UseSerialization<JsonSerializer>()
    .Encoding(noBomEncoding);

Bson

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

Samples


Last modified