This sample uses the System.Text.Json serializer built in to NServiceBus to serialize message payloads.
Configuring to use NServiceBus.Newtonsoft.Json
endpointConfiguration.UseSerialization<SystemJsonSerializer>();
Sending the message
var message = new CreateOrder
{
OrderId = 9,
Date = DateTime.Now,
CustomerId = 12,
OrderItems = new List<OrderItem>
{
new OrderItem
{
ItemId = 6,
Quantity = 2
},
new OrderItem
{
ItemId = 5,
Quantity = 4
},
}
};
await endpointInstance.SendLocal(message);
Output
{
"OrderId": 9,
"Date": "2015-09-15T10:23:44.9367871+10:00",
"CustomerId": 12,
"OrderItems": [
{
"ItemId": 6,
"Quantity": 2
},
{
"ItemId": 5,
"Quantity": 4
}
]
}