Skip to content

Fix Optional deserializer not deserializing non-guessable types (such as Int32)

Mateusz Brawański requested to merge github/fork/uwx/patch-72 into master

Created by: uwx

Summary

Because of an oversight haHAA in Optional deserialization code, attempting to deserialize an integer type would fail, get catched by the try-catch and return the default value. In VS, when setting all exceptions to break, the error would pop up quite often.

Details

I just found out that you can't directly convert between a boxed type and a different unboxed type. Json.NET always represents number values in JSON as Int64, so when deserializing the DiscordEmbed.Color property, the Optional(object) constructor would try to convert it from object (boxing an Int64) to Int32 and fail miserably. Because the exception is caught and silently ignored, finding the culpirit was REALLY ANNOYING.

Changes proposed

  • Fix Optional deserializer not deserializing non-guessable types (such as Int32), by preemptively converting them to the right type and using the generic constructor
  • Remove now-unused Optional(object) constructor

Notes

All it took was one goddamn pull request and I've never heard the end of it.

Merge request reports

Loading