VaultSharp.V1.SecretsEngines.Database: JsonException when deserializing a numeric rotation_period
See original GitHub issueDescribe the bug
According to the Hashicorp documentation, the rotation_period
can be stored as a string or an int. However, System.Text.Json
(contrary to Newtonsoft.Json
) does not accept non-string values when deserializing to properties of type string (in this case, VaultSharp.V1.SecretsEngines.Database.RotationPeriod
).
Since our rotation_period
is stored as a number, we’re being hit with a JsonException
whenever we try to obtain our credentials using GetStaticCredentialsAsync
on the latest version of the library.
Database Secrets Engine (rotation_period): https://developer.hashicorp.com/vault/api-docs/secret/databases#rotation_period System.Text.Json migration (non-string values): https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/migrate-from-newtonsoft?pivots=dotnet-7-0#non-string-values-for-string-properties
VaultSharp Version 1.13.0
Exception Details/Stack Trace/Error Message System.Text.Json.JsonException: ‘The JSON value could not be converted to System.String. Path: $.rotation_period | LineNumber: 0 | BytePositionInLine: 255.’ InvalidOperationException: Cannot get the value of a token type ‘Number’ as a string.
Any additional info I’m thinking a solution would be to create a custom converter that handles converting non-string values to string (similar to how Newtonsoft.Json does it) and then register the JsonConverter on the RotationPeriod property. Idea taken from: https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/converters-how-to?pivots=dotnet-7-0#registration-sample---jsonconverter-on-a-property
Issue Analytics
- State:
- Created 6 months ago
- Comments:5 (3 by maintainers)
Very cool. I’ll publish it out in a day.
hi @RatserX ,
i published the fix as a beta package: https://www.nuget.org/packages/VaultSharp/1.13.0.1-beta1 Can you try and let me know if any issues? If none, I’ll publish the proper version