title | summary | related | |
---|---|---|---|
JSON Serializer |
A json serializer that uses Json.NET. |
|
Using Json via an ILMerged copy of Json.NET.
snippet:JsonSerialization
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 |
Since Json.net is ILMerged the Json.net customization attributes are not supported. However certain customizations are still supported via standard .NET attributes.
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"}
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.
snippet:BsonSerialization