From d4aade4e866556f8a11ed05756ab8b01f2ed0e71 Mon Sep 17 00:00:00 2001 From: Matthew Bogner Date: Tue, 12 Dec 2023 13:06:22 -0600 Subject: [PATCH] Fix PutIndexTemplateRequest deserialization (#765) * Fix PutIndexTemplateRequest deserialization Signed-off-by: Matthew Bogner * CHANGELOG.md Signed-off-by: Matthew Bogner * spotless Signed-off-by: Matthew Bogner --------- Signed-off-by: Matthew Bogner --- CHANGELOG.md | 1 + .../indices/PutIndexTemplateRequest.java | 1 + .../core/PutIndexTemplateRequestTest.java | 31 +++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 java-client/src/test/java/org/opensearch/client/opensearch/core/PutIndexTemplateRequestTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 57d0e388e0..43753f96ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ This section is for maintaining a changelog for all breaking changes for the cli ### Fixed - Fix version and build ([#254](https://github.com/opensearch-project/opensearch-java/pull/254)) - Fix PutTemplateRequest field deserialization ([#723](https://github.com/opensearch-project/opensearch-java/pull/723)) +- Fix PutIndexTemplateRequest field deserialization ([#765](https://github.com/opensearch-project/opensearch-java/pull/765)) ### Security diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/indices/PutIndexTemplateRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/indices/PutIndexTemplateRequest.java index 91b61e989d..77cbb67391 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/indices/PutIndexTemplateRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/indices/PutIndexTemplateRequest.java @@ -406,6 +406,7 @@ protected static void setupPutIndexTemplateRequestDeserializer(ObjectDeserialize op.add(Builder::priority, JsonpDeserializer.integerDeserializer(), "priority"); op.add(Builder::template, IndexTemplateMapping._DESERIALIZER, "template"); op.add(Builder::version, JsonpDeserializer.longDeserializer(), "version"); + op.add(Builder::name, JsonpDeserializer.stringDeserializer(), "name"); } diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/core/PutIndexTemplateRequestTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/core/PutIndexTemplateRequestTest.java new file mode 100644 index 0000000000..eb95320333 --- /dev/null +++ b/java-client/src/test/java/org/opensearch/client/opensearch/core/PutIndexTemplateRequestTest.java @@ -0,0 +1,31 @@ +package org.opensearch.client.opensearch.core; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.StringReader; +import java.util.List; +import java.util.Map; +import org.junit.Assert; +import org.junit.Test; +import org.opensearch.client.json.JsonpMapper; +import org.opensearch.client.json.jsonb.JsonbJsonpMapper; +import org.opensearch.client.opensearch.indices.PutIndexTemplateRequest; + +public class PutIndexTemplateRequestTest extends Assert { + + @Test + public void deserialize_validFieldsIncluded_RequestIsBuilt() throws JsonProcessingException { + final JsonpMapper mapper = new JsonbJsonpMapper(); + final Map indexTemplateMap = Map.of("name", "test", "index_patterns", "*", "create", true, "priority", 1); + + final String indexTemplate = new ObjectMapper().writeValueAsString(indexTemplateMap); + final var parser = mapper.jsonProvider().createParser(new StringReader(indexTemplate)); + + final PutIndexTemplateRequest putIndexTemplateRequest = PutIndexTemplateRequest._DESERIALIZER.deserialize(parser, mapper); + + assertEquals(putIndexTemplateRequest.name(), "test"); + assertEquals(putIndexTemplateRequest.indexPatterns(), List.of("*")); + assertEquals((int) putIndexTemplateRequest.priority(), 1); + } + +}