From 905aa34b82cd136db26cb241782c2aaa3d4f6360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beniamin=20J=C4=99drychowski?= Date: Mon, 29 Jul 2024 08:14:24 +0200 Subject: [PATCH] Default normalizer deserialization to custom type when unspecified (#1111) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Default normalizer deserialization to custom type when unspecified Signed-off-by: beniamin.jedrychowsk * fix style Signed-off-by: beniamin.jedrychowsk * Update CHANGELOG.md fixed changelog formatting Co-authored-by: Thomas Farr Signed-off-by: Beniamin Jędrychowski --------- Signed-off-by: beniamin.jedrychowsk Signed-off-by: Beniamin Jędrychowski Co-authored-by: Thomas Farr --- CHANGELOG.md | 3 ++- .../_types/analysis/Normalizer.java | 2 +- .../analysis/NormalizerDeserializerTest.java | 24 +++++++++++++++++++ 3 files changed, 27 insertions(+), 2 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..f91dd824b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +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 @@ -512,4 +513,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..5c9d7c7a13 --- /dev/null +++ b/java-client/src/test/java/org/opensearch/client/opensearch/_types/analysis/NormalizerDeserializerTest.java @@ -0,0 +1,24 @@ +/* + * 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)); + } +}