Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite Event.DeserializationStrategy (#923)
When deserializing Events, Event.DeserializationStrategy assumed that the d field [1] was the last field to be observed. If it wasn't the last field, the deserialization could fail in two ways: * the t and s fields were ignored if they came after the d field * an exception was thrown if the op field came after the d field To fix these possible failure cases, the deserialization logic has been changed to work in two steps: 1. decode all fields regardless of order, treating the d field as a plain JsonElement 2. after all fields have been decoded, construct an Event from the JsonElement, depending on the values of the op, t and s fields The supertype of Event.DeserializationStrategy has also been changed from DeserializationStrategy<Event?> to DeserializationStrategy<Event> - deserialize no longer returns null in some cases of illegal event payloads, but throws exceptions instead. Fixes #922 [1] https://discord.com/developers/docs/topics/gateway-events#payload-structure Co-authored-by: Michael Rittmeister <[email protected]>
- Loading branch information