Skip to content

Commit

Permalink
fix: correctly get string label value for each jsonNode types (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanket-mundra authored Aug 11, 2024
1 parent 39ea48e commit 4f62e48
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ public List<DocStoreMetric> getCustomMetrics(final CustomMetricConfig customMetr
jsonNodeMap.entrySet().iterator(), Spliterator.ORDERED),
false)
.filter(entry -> !VALUE_KEY.equals(entry.getKey()))
.collect(toUnmodifiableMap(Entry::getKey, entry -> entry.getValue().textValue()));
.collect(
toUnmodifiableMap(
Entry::getKey, entry -> getStringLabelValue(entry.getValue())));

final DocStoreMetric metric =
DocStoreMetric.builder()
Expand All @@ -119,4 +121,18 @@ public List<DocStoreMetric> getCustomMetrics(final CustomMetricConfig customMetr
return emptyList();
}
}

private String getStringLabelValue(JsonNode jsonNode) {
switch (jsonNode.getNodeType()) {
case STRING:
return jsonNode.textValue();
case NUMBER:
return String.valueOf(jsonNode.numberValue());
case BOOLEAN:
return String.valueOf(jsonNode.booleanValue());
default:
throw new IllegalArgumentException(
String.format("Unsupported JSON node type: %s", jsonNode.getNodeType()));
}
}
}

0 comments on commit 4f62e48

Please sign in to comment.