From 10f2928551afb53fdd755974c2dfd7776e2b298b Mon Sep 17 00:00:00 2001 From: "beniamin.jedrychowsk" Date: Thu, 25 Jul 2024 18:02:58 +0200 Subject: [PATCH 1/3] Default normalizer deserialization to custom type when unspecified Signed-off-by: beniamin.jedrychowsk --- CHANGELOG.md | 4 +-- .../_types/analysis/Normalizer.java | 2 +- .../analysis/NormalizerDeserializerTest.java | 25 +++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 java-client/src/test/java/org/opensearch/client/opensearch/_types/analysis/NormalizerDeserializerTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index c6093bfe19..0c7d55c562 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,7 +40,7 @@ This section is for maintaining a changelog for all breaking changes for the cli ### Removed ### Fixed - +- Fixed error when deserializing a normalizer without 'type' [#1111](https://github.com/opensearch-project/opensearch-java/pull/1111) ### Security ## [2.12.0] - 07/22/2024 @@ -512,4 +512,4 @@ This section is for maintaining a changelog for all breaking changes for the cli [2.5.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.4.0...v2.5.0 [2.4.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.3.0...v2.4.0 [2.3.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.2.0...v2.3.0 -[2.2.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.1.0...v2.2.0 \ No newline at end of file +[2.2.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.1.0...v2.2.0 diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/analysis/Normalizer.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/analysis/Normalizer.java index de7342afcd..a357215809 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/analysis/Normalizer.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/analysis/Normalizer.java @@ -186,7 +186,7 @@ protected static void setupNormalizerDeserializer(ObjectDeserializer op op.add(Builder::custom, CustomNormalizer._DESERIALIZER, "custom"); op.add(Builder::lowercase, LowercaseNormalizer._DESERIALIZER, "lowercase"); - op.setTypeProperty("type", null); + op.setTypeProperty("type", Kind.Custom.jsonValue()); } diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/_types/analysis/NormalizerDeserializerTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/_types/analysis/NormalizerDeserializerTest.java new file mode 100644 index 0000000000..81edbc2890 --- /dev/null +++ b/java-client/src/test/java/org/opensearch/client/opensearch/_types/analysis/NormalizerDeserializerTest.java @@ -0,0 +1,25 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.client.opensearch._types.analysis; + +import org.junit.Test; +import org.opensearch.client.opensearch.model.ModelTestCase; + +public class NormalizerDeserializerTest extends ModelTestCase { + @Test + public void deserializesTypelessCustomAnalyzer() { + String json = "{\n" + + " \"filter\": \"lowercase\"\n" + + " }"; + + Normalizer normalizer = fromJson(json, Normalizer._DESERIALIZER); + assertTrue(normalizer.isCustom()); + assertEquals("lowercase", normalizer.custom().filter().get(0)); + } +} From 6cb4e10acd589c849a6bdcff9bb27f0bf4817018 Mon Sep 17 00:00:00 2001 From: "beniamin.jedrychowsk" Date: Thu, 25 Jul 2024 18:09:24 +0200 Subject: [PATCH 2/3] fix style Signed-off-by: beniamin.jedrychowsk --- .../_types/analysis/NormalizerDeserializerTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/_types/analysis/NormalizerDeserializerTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/_types/analysis/NormalizerDeserializerTest.java index 81edbc2890..5c9d7c7a13 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/_types/analysis/NormalizerDeserializerTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/_types/analysis/NormalizerDeserializerTest.java @@ -12,11 +12,10 @@ import org.opensearch.client.opensearch.model.ModelTestCase; public class NormalizerDeserializerTest extends ModelTestCase { + @Test public void deserializesTypelessCustomAnalyzer() { - String json = "{\n" + - " \"filter\": \"lowercase\"\n" + - " }"; + String json = "{\n" + " \"filter\": \"lowercase\"\n" + " }"; Normalizer normalizer = fromJson(json, Normalizer._DESERIALIZER); assertTrue(normalizer.isCustom()); From 37cce2d0461a749d16e1f044ac47271945eb9b35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beniamin=20J=C4=99drychowski?= Date: Mon, 29 Jul 2024 08:03:15 +0200 Subject: [PATCH 3/3] Update CHANGELOG.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixed changelog formatting Co-authored-by: Thomas Farr Signed-off-by: Beniamin Jędrychowski --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c7d55c562..f91dd824b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,7 +40,8 @@ This section is for maintaining a changelog for all breaking changes for the cli ### Removed ### Fixed -- Fixed error when deserializing a normalizer without 'type' [#1111](https://github.com/opensearch-project/opensearch-java/pull/1111) +- Fixed error when deserializing a normalizer without 'type' ([#1111](https://github.com/opensearch-project/opensearch-java/pull/1111)) + ### Security ## [2.12.0] - 07/22/2024