mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-03 22:23:16 +00:00
Minor: JsonUtils.extractValue shouldn't throw exceptions (#18554)
This commit is contained in:
parent
9d9eccedda
commit
a03d915909
@ -517,14 +517,17 @@ public final class JsonUtils {
|
|||||||
|
|
||||||
public static <T> T extractValue(String jsonResponse, String... keys) {
|
public static <T> T extractValue(String jsonResponse, String... keys) {
|
||||||
JsonNode jsonNode = JsonUtils.readTree(jsonResponse);
|
JsonNode jsonNode = JsonUtils.readTree(jsonResponse);
|
||||||
|
|
||||||
// Traverse the JSON structure using keys
|
|
||||||
for (String key : keys) {
|
for (String key : keys) {
|
||||||
jsonNode = jsonNode.path(key);
|
jsonNode = jsonNode.path(key);
|
||||||
}
|
}
|
||||||
|
if (jsonNode.isMissingNode() || jsonNode.isNull()) {
|
||||||
// Extract the final value
|
return null;
|
||||||
return JsonUtils.treeToValue(jsonNode, (Class<T>) getValueClass(jsonNode));
|
}
|
||||||
|
try {
|
||||||
|
return JsonUtils.treeToValue(jsonNode, (Class<T>) getValueClass(jsonNode));
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T extractValue(JsonNode jsonNode, String... keys) {
|
public static <T> T extractValue(JsonNode jsonNode, String... keys) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user