From b06b6488ed0b44370838268974dac4d299f3f4a7 Mon Sep 17 00:00:00 2001 From: Alex Dunn <75815303+alexdunnjpl@users.noreply.github.com> Date: Mon, 9 Oct 2023 10:09:15 -0700 Subject: [PATCH] replace default string representation of Iterable fields with pipe-delimited format (#380) affects application/csv, application/kvp+json, and text/csv return types fixes #375 --- .../registry/model/WyriwygBusinessObject.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/service/src/main/java/gov/nasa/pds/api/registry/model/WyriwygBusinessObject.java b/service/src/main/java/gov/nasa/pds/api/registry/model/WyriwygBusinessObject.java index 08cdfd48..1f22789b 100644 --- a/service/src/main/java/gov/nasa/pds/api/registry/model/WyriwygBusinessObject.java +++ b/service/src/main/java/gov/nasa/pds/api/registry/model/WyriwygBusinessObject.java @@ -111,7 +111,7 @@ public int setResponse(SearchHits hits, Summary summary, List fields) { WyriwygProductKeyValuePair kvp = new WyriwygProductKeyValuePair(); try { kvp.setKey(SearchUtil.openPropertyToJsonProperty(pair.getKey())); - kvp.setValue(String.valueOf(pair.getValue())); + kvp.setValue(getStringValueOf(pair.getValue())); product.addKeyValuePairsItem(kvp); } catch (UnsupportedSearchProperty e) { log.warn("openSearch property " + pair.getKey() + " is not supported, ignored"); @@ -125,4 +125,21 @@ public int setResponse(SearchHits hits, Summary summary, List fields) { this.products = products; return (int) (hits.getTotalHits().value); } + + private String getStringValueOf(Object o) { + String valueOf; + if (o instanceof Iterable) { + List stringRepresentations = new ArrayList<>(); + for (Object el : (Iterable) o ) { + stringRepresentations.add(String.valueOf(el)); + } + + String delimiter = "|"; + valueOf = String.join(delimiter, stringRepresentations); + } else { + valueOf = String.valueOf(o); + } + + return valueOf; + } }