fix type conversion in SecretResponse getter method (#67)
Some checks failed
continuous-integration/drone/push Build is failing
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:
@ -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());
|
||||
}
|
||||
|
Reference in New Issue
Block a user