✅ Serializing a dictonary without path in root object
Hello, I'm trying to create a DTO for an API, where the request takes a dictornary of values, but the "keys" are part of the root object, and not under a path.
{ // Defined key value pairs "name": "Foo", "path": "Bar", // A map of language code to content "en": {}, "de": {}, "fr": {}, }
{ // Defined key value pairs "name": "Foo", "path": "Bar", // A map of language code to content "en": {}, "de": {}, "fr": {}, }
I'm therefor not sure how I can create a C# DTO, where the json output will like the example. If I serilize the below, the language codes will be
languageMap.en
languageMap.en
etc, which does not match the request object
public class MyDto{ [JsonPropertyName("name")] public string Name { get; set; } = null!; [JsonPropertyName("path")] public string Path { get; set; } = null!; public Dictionary<string, object> LanguageMap { get; set; } = null!;}
public class MyDto{ [JsonPropertyName("name")] public string Name { get; set; } = null!; [JsonPropertyName("path")] public string Path { get; set; } = null!; public Dictionary<string, object> LanguageMap { get; set; } = null!;}
Is there a solution on how to serilize the dictionary into the root object, without ot being under the path?