From 7ab6bbe7a07fb6cd29122774153bcdc76c1fac2f Mon Sep 17 00:00:00 2001 From: labkey-susanh Date: Wed, 27 Sep 2023 08:30:00 -0700 Subject: [PATCH] Allow for JSON array objects in name generation data and improve error messaging --- api/src/org/labkey/api/data/NameGenerator.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/api/src/org/labkey/api/data/NameGenerator.java b/api/src/org/labkey/api/data/NameGenerator.java index 04d23d49ac2..32d7dab5751 100644 --- a/api/src/org/labkey/api/data/NameGenerator.java +++ b/api/src/org/labkey/api/data/NameGenerator.java @@ -19,6 +19,7 @@ import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.json.JSONArray; import org.junit.After; import org.junit.Assert; import org.junit.Test; @@ -668,9 +669,13 @@ else if (value instanceof Collection) Collection coll = (Collection)value; values = coll.stream().map(String::valueOf); } + else if (value instanceof JSONArray jsonArray) + { + values = jsonArray.toList().stream().map(String::valueOf); + } else { - throw new IllegalStateException("Expected string or collection for '" + parentColName + "': " + value); + throw new IllegalStateException("For parent values in naming pattern, expected string or collection for '" + parentColName + "': " + value); } return values