Skip to content

Commit

Permalink
fix: serialize ConsequenceParams empty query (#766)
Browse files Browse the repository at this point in the history
  • Loading branch information
aallam committed Jan 6, 2022
1 parent f41e062 commit 01b0bcd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.algolia.search.models.rules;

import com.algolia.search.Defaults;
import com.algolia.search.util.AlgoliaUtils;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
Expand Down Expand Up @@ -80,7 +79,7 @@ public void serialize(ConsequenceQuery value, JsonGenerator gen, SerializerProvi
* Consequence query edits will override regular "query" - both can't be set at the same time
* https://www.algolia.com/doc/api-reference/api-methods/save-rule/#method-param-query
* */
if (!AlgoliaUtils.isNullOrEmptyWhiteSpace(value.getQueryString())) {
if (value.getQueryString() != null) {
gen.writeString(value.getQueryString());
} else {
gen.writeStartObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1010,4 +1010,11 @@ void recommendations() throws JsonProcessingException {
assertThat(recommendHit.getObjectID()).isEqualTo("D05927-8161-111");
assertThat(recommendHit.getScore()).isEqualTo(32.72f);
}

@Test
void consequenceParams_emptyQuery_nullEdits() throws JsonProcessingException {
ConsequenceParams params = new ConsequenceParams().setQuery("");
String json = Defaults.getObjectMapper().writeValueAsString(params);
assertThat(json).isEqualTo("{\"query\":\"\"}");
}
}

0 comments on commit 01b0bcd

Please sign in to comment.