francoisa
12/15/2022, 9:21 AM@ScalarFunction(nullableParameters = true)
public static String jsonPathString(@Nullable Object object, String jsonPath, String defaultValue) {
try {
Object jsonValue = jsonPath(object, jsonPath);
if (jsonValue instanceof String) {
return (String) jsonValue;
}
return jsonValue == null ? defaultValue : JsonUtils.objectToString(jsonValue);
} catch (Exception ignore) {
return defaultValue;
}
}
to
@ScalarFunction(nullableParameters = true)
public static String jsonPathString(@Nullable Object object, String jsonPath, String defaultValue) {
try {
Object jsonValue = jsonPath(object, jsonPath);
if ((jsonValue instanceof String) && (!String.valueOf(jsonValue).isBlank())) {
return (String) jsonValue;
}
return jsonValue == null || String.valueOf(jsonValue).isBlank()
? defaultValue : JsonUtils.objectToString(jsonValue);
} catch (Exception ignore) {
return defaultValue;
}
}
Doing that allow me to set a default value on the blank string also. Thats can be helpfull on many use cases. Is that interesting to get that as a PR ? If not do I have a way to surcharge this with a provided jar or something easy to integrate ?francoisa
01/16/2023, 1:39 PM