mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-31 20:51:26 +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) {
|
||||
JsonNode jsonNode = JsonUtils.readTree(jsonResponse);
|
||||
|
||||
// Traverse the JSON structure using keys
|
||||
for (String key : keys) {
|
||||
jsonNode = jsonNode.path(key);
|
||||
}
|
||||
|
||||
// Extract the final value
|
||||
return JsonUtils.treeToValue(jsonNode, (Class<T>) getValueClass(jsonNode));
|
||||
if (jsonNode.isMissingNode() || jsonNode.isNull()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return JsonUtils.treeToValue(jsonNode, (Class<T>) getValueClass(jsonNode));
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T extractValue(JsonNode jsonNode, String... keys) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user