I have an object with a decimal in:
public class MyObject
{
[JsonProperty(PropertyName = "some_amount")]
public decimal Amount { get; set; }
}
When I call my implementation of MassTransit's IPublishEndpoint.Publish(myObject)
the message that actually goes on the queue is similar to this:
{
...
"message":{
"Amount":"0.1"
}
...
}
Yet when I use JsonConvert.SerializeObject(myObject)
I get the following:
{
"Amount":0.1
}
Ignoring the container object that is included by MassTransit, you can see MyObject's decimal property is in quotations when sent via MassTransit but without them when using Newtonsoft.Json.
I would like MassTransit to serialize my decimal property without the quotations, as a number rather than as a string -- i.e. the same way it get serialized when I serialize the object directly with JsonConvert.SerializeObject
. What is the best way to achieve this? I don't want to go re-inventing the wheel if there's a more simplistic route.
Also, is this happening because by default MassTransit serializes decimals to strings? If so, why is this and why haven't Newtonsoft followed for the same reason?