Add serializer for Optional<T> that includes the property only if a value is present / make Modify Guild/Member endpoint parameters optional / implement Guild.SystemChannel
Created by: uwx
Summary
This is a proof of concept solution for the problem explored in detail in #222, and commented in passing earlier in #165 (closed):
Details
It uses a custom JsonConverter for Optional<T>
(originally just Optional<Nullable<struct>>
), that only includes the serialized property in the JSON output if the Optional's value is present. With my solution, you can simply use Optional<struct?>
or Optional<Nullable<struct>>
. This replaces the original buggy Optional serialization, which would throw an exception if the value was not present.
Usage
I've created a class, DSharpPlus.Net.Serialization.DiscordJson
that can be used as a drop-in replacement for JsonConvert
for calls to JsonConvert.SerializeObject
.