From c0efd41a4cf6d8b30c29cdd10316fdadd1c579ff Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Mon, 29 Jul 2024 23:52:29 +1200 Subject: [PATCH] Default normalizer deserialization to custom type when unspecified (#1111) (#1114) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Default normalizer deserialization to custom type when unspecified * fix style * Update CHANGELOG.md fixed changelog formatting --------- (cherry picked from commit 905aa34b82cd136db26cb241782c2aaa3d4f6360) Signed-off-by: beniamin.jedrychowsk Signed-off-by: Beniamin Jędrychowski Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] Co-authored-by: Thomas Farr --- CHANGELOG.md | 1 + .../_types/analysis/Normalizer.java | 2 +- .../analysis/NormalizerDeserializerTest.java | 24 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) 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 62ddcb5839..6887494566 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Removed ### Fixed +- Fixed error when deserializing a normalizer without 'type' ([#1111](https://github.com/opensearch-project/opensearch-java/pull/1111)) ### Security 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)); + } +}