Consider the Node
class. Using Newtonsoft to convert it into the JSON.
class Node {
IList<Node> Nodes { get; }
}
I'm currently implementing default sorting logic as -
class Node : IComparable<Node> {
IList<Node> Nodes { get; }
public int CompareTo(Node node) {
// some default sorting logic
}
}
Newtonsoft, while serializing using it, and giving JSON with Nodes sorted in same logic.
string jsonString = JsonConvert.SerializeObject(
deserializedObject,
Formatting.None,
new JsonSerializerSettings
{
// some settings
});
Question: Now, I want to pass something like IComparer
to JsonConvert.SerializeObject()
method, so that JSON should have Nodes collection in a new sorting logic.
In some way I want to give freedom to caller to sort the collection in their way rather than default one, which would be used otherwise.
Don't know if there is a easy way of doing it? Any suggestions please?