Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace default string representation of Iterable fields with pipe-delimited format for some Accepts types #380

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -111,7 +111,7 @@ public int setResponse(SearchHits hits, Summary summary, List<String> 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<String> fields) {
this.products = products;
return (int) (hits.getTotalHits().value);
}

private String getStringValueOf(Object o) {
String valueOf;
if (o instanceof Iterable) {
List<String> stringRepresentations = new ArrayList<>();
for (Object el : (Iterable<Object>) o ) {
stringRepresentations.add(String.valueOf(el));
}

String delimiter = "|";
valueOf = String.join(delimiter, stringRepresentations);
} else {
valueOf = String.valueOf(o);
}

return valueOf;
}
}