As known it's better to use string format to serialize decimal number. https://stackoverflow.com/a/38357877/4805491
Many services send decimal values as strings and Json.NET
deserializes it well.
But I can't find how to serialize decimal with string format?
Should I make custom JsonConverter
for all decimal numbers? Or there are ways to do it with default Json.NET
opportunities?
Updated
I need this test to be passed.
So, I need to replace all decimal values with string values when or after
JToken.FromObject( ... )
is called.
var json = await Client.RequestJsonAsync( desc, default );
var obj = json.ToObject<MyObject>();
var json2 = JToken.FromObject( obj );
Assert.IsTrue( JToken.DeepEquals( json, json2 ), "Jsons are not equal" );
Unfortunately there is no (or I can't find) method to all replace all nodes in hierarchy. JToken.Replace
only replaces itself. Also I don't see a way to iterating within hierarchy.