Given this program:
using System;
using System.Collections.Generic;
using System.Text.Json;
public class Program
{
public static void Main()
{
var payload = new Payload();
payload.Id = "1001";
payload.PassthroughParameters.Add("Foo", "Bar");
var jsonString = JsonSerializer.Serialize(payload, new JsonSerializerOptions {
WriteIndented = true
});
Console.WriteLine(jsonString);
// OUTPUTS:
// {
// "Id": "1001",
// "PassthroughParameters": {
// "Foo": "Bar"
// }
// }
}
public class Payload
{
public string Id { get; set; }
public IDictionary<string, string> PassthroughParameters { get; set; } = new Dictionary<string, string>();
}
}
What's the most abstract C# data structure I can replace IDictionary<string, string>
with that serializes to the same JSON?
I want to make it harder to reference the contents of the data structure in the C# code (e.g. payload.PassthroughParameters["Foo"]
) to avoid coupling for code maintenance (not a security concerns) while still being able to pass the entire thing to an internal process (e.g. Process(otherParams, payload.PassthroughParameters)
).