bored-oyster-3147
12/15/2020, 6:48 PMIDictionary<string, StackSettingsConfigValue> Config { get; }
.
The StackSettingsConfigValue
looks like:
{
string? ValueString,
IDictionary<string, object>? ValueObject,
bool IsSecure,
bool IsObject
}
This allows us to deserialize a structured object provided to stack settings config in a shape that isn't known at compile time. There is a catch though. Since both System.Text.Json
and YamlDotNet
deserialize to a dictionary differently, the compile-time type of ValueObject
must remain Dictionary<string, object>
in order to support both formats, since we don't want JSON or YAML to be exposed on StackSettingsConfigValue
. But the runtime-type will be different depending on what format we are deserializing.
Coming from JSON with System.Text.Json
, the type of TValue
at runtime will always be JsonElement
.
For good measure I tried Newtonsoft.Json
, and this library tries to determine the type if it is a primitive, but only at the first level of depth. So if the property is a .NET primitive it will be that type - I tried and got long
or double
for numbers depending on if there is a decimal, as well as bool
& string
. But if the property is itself an object, than rather than getting another nested Dictionary
you instead receive Newtonsoft's type JObject
.
Coming from YAML with YamlDotNet
, the type of TValue
at runtime is always a string
, but it will break apart nested objects. So you receive either string
or Dictionary<string, string>
depending on if the property itself is an object.
So questions, are we OK with this implementation? Are we OK with the runtime type being different depending on which format we're deserializing from? Do we prefer Newtonsoft's method over System.Text.Json? Honestly I prefer System.Text.Json's just because it is consistent across all depths, but it does mean that the json-specific Type is exposed right away (at runtime).lemon-agent-27707
12/15/2020, 9:38 PMbored-oyster-3147
12/15/2020, 9:42 PMGetStackSettings
and then SaveStackSettings
with the same object after making any changes (even if those changes weren't to config) they will possibly have issues. If it was JSON, the save will try to serialize JsonElement
which I think will be fine since System.Text.Json
can do that out of the box. But if it is YAML than they may lose some context since everything is deserialized as a string
and will then be serialized as suchtall-librarian-49374
12/15/2020, 10:23 PMbored-oyster-3147
12/15/2020, 10:33 PMtall-librarian-49374
12/15/2020, 10:36 PMbored-oyster-3147
12/15/2020, 10:39 PMlemon-agent-27707
12/15/2020, 10:59 PMWorkDir
.bored-oyster-3147
12/15/2020, 11:04 PMlemon-agent-27707
12/16/2020, 12:11 AMbored-oyster-3147
12/16/2020, 12:33 AMlemon-agent-27707
12/16/2020, 4:26 PM