ViewQuery key(String) method appending double quotes



Hi Couchbase Team,
I am passing key as string to the view query to get the result. But i am getting no records. I enquired the view query request, and found that the key params appended with additional double quotes(%22) at the beginning and end. Kindly help me to fix this.

String key = “[“18F09BBE665940559AE54EE183E19C65”,“DIM”,“DIM_TYPE”,“DIM_VALUE”,“FAVORITE”]”;
ViewQuery query = ViewQuery.from(designDocName, viewName);

Original request:
2018-06-11 15:20:38 DEBUG CouchBaseProvider:354 - queryViewByKey query: ViewQuery(designDocName/viewName){params=“stale=false&key=%22%5B%2218F09BBE665940559AE54EE183E19C65%22%2C%22DIM%22%2C%22DIM_TYPE%22%2C%22DIM_VALUE%22%2C%22FAVORITE%22%5D**%22**”}

Expected request:
2018-06-11 15:20:38 DEBUG CouchBaseProvider:354 - queryViewByKey query: ViewQuery(designDocName/viewName){params=“stale=false&key=%5B%2218F09BBE665940559AE54EE183E19C65%22%2C%22DIM%22%2C%22DIM_TYPE%22%2C%22DIM_VALUE%22%2C%22FAVORITE%22%5D”}


So you are passing a JSON array in as a string so the SDK will quote it again. Try passing it in as a JsonArray with those elements instead.



Yes. we are passing JSON array as a whole string. Now I coded to convert back the whole string to JSON array as below and passing the request. Now i can able to retrieve the data.

public JsonArray getJsonArrayKey(String key) {
String keyWithoutDoubleQuotesAndBrackets= key.replaceAll("[\["\]]", “”);
String[] strArray = StringUtils.split(keyWithoutDoubleQuotesAndBrackets, “,”);
return JsonArray.from(strArray);