fix regression from redundant String mapping in SecretResponse getter
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Mapping a JSON string into String using a JSON parser will fail, so we should use the string directly instead of applying double conversion. Fixes: f3e1f01e38aa74ed20a8ca382e6821b540eb475c
This commit is contained in:
parent
f3e1f01e38
commit
1195b447a2
@ -83,8 +83,12 @@ public abstract class SecretResponse extends VaultDataResponse {
|
||||
return type.cast(rawValue);
|
||||
} else {
|
||||
var om = new ObjectMapper();
|
||||
if (rawValue instanceof String) {
|
||||
return om.readValue((String) rawValue, type);
|
||||
} else {
|
||||
return om.readValue(om.writeValueAsString(rawValue), type);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new InvalidResponseException("Unable to parse response payload: " + e.getMessage());
|
||||
}
|
||||
|
@ -119,7 +119,8 @@ class PlainSecretResponseTest extends AbstractModelTest<PlainSecretResponse> {
|
||||
" \"" + complexKey + "\": {" +
|
||||
" \"field1\": \"" + complexVal.field1 + "\",\n" +
|
||||
" \"field2\": " + complexVal.field2 + "\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" \"" + complexKey + "Json\": \"" + objectMapper.writeValueAsString(complexVal).replace("\"", "\\\"") + "\"\n" +
|
||||
" }\n" +
|
||||
"}",
|
||||
PlainSecretResponse.class
|
||||
@ -169,6 +170,11 @@ class PlainSecretResponseTest extends AbstractModelTest<PlainSecretResponse> {
|
||||
() -> res.get(complexKey, Integer.class),
|
||||
"getting complex type as integer should fail"
|
||||
);
|
||||
assertEquals(
|
||||
complexVal,
|
||||
assertDoesNotThrow(() -> res.get(complexKey + "Json", ComplexType.class), "getting complex type from JSON string failed"),
|
||||
"unexpected value for complex type from JSON string"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user