Only some enum values are interpreted as bytes, and not string, in custom JsonConverter. #94223
-
DescriptionCode is based on the documentation here: When trying to deserialize some JSON data with a with a certain enum value, a custom JsonConverter looks at the the enum value as a bytes array and not a string. Changing the enum value to a different value makes the JsonConverter interpret it as a string. The converter is set to return an object and will be used with other types than the reproduction steps puts forward. So it is meant to be given a range of different types other than QueryCondition2. Reproduction Steps
Expected behaviorI expect the custom JsonConverter to act the same on the enum value, each time, Actual behaviorThe reproduction test BlockLevelEnumQueryCondition returns this on enum value "John" Message: Regression?No response Known WorkaroundsNo response Configuration.NET 6 Other informationNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The issue seems to be with this code in your custom converter: JsonTokenType.String when reader.TryGetBytesFromBase64(out byte[] bytes) => bytes,
JsonTokenType.String => reader.GetString()!, Because |
Beta Was this translation helpful? Give feedback.
True base64 (vs base64url) always requires a multiple of 4 characters; so "John" is valid, "Johns" is not. Both base64s only have 64 valid characters, and neither of them considers ¡ a valid character, so "¡¡¡¡" is another example of an invalid base64 string.
In the grand universe of all possible strings, the "invalid base64" strings vastly outnumber the "valid base64" strings.