fix type conversion in SecretResponse getter method (#67)
Some checks failed
continuous-integration/drone/push Build is failing

Converting the payload using toString() is not an appropriate way to
feed a JSON parser. We now use JSON roundtrip for type mapping and
introduce shortcuts of the type already matches the target type.
This commit is contained in:
2023-06-16 17:43:01 +02:00
parent 622b13f508
commit f3e1f01e38
4 changed files with 142 additions and 3 deletions

View File

@ -79,8 +79,12 @@ public abstract class SecretResponse extends VaultDataResponse {
Object rawValue = get(key);
if (rawValue == null) {
return null;
} else if (type.isInstance(rawValue)) {
return type.cast(rawValue);
} else {
var om = new ObjectMapper();
return om.readValue(om.writeValueAsString(rawValue), type);
}
return new ObjectMapper().readValue(rawValue.toString(), type);
} catch (IOException e) {
throw new InvalidResponseException("Unable to parse response payload: " + e.getMessage());
}