diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e91c2d05c..62aaf86987 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,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)) ### Security diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/indices/PutTemplateRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/indices/PutTemplateRequest.java index 9ba6e65283..295d840473 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/indices/PutTemplateRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/indices/PutTemplateRequest.java @@ -586,8 +586,10 @@ public PutTemplateRequest build() { protected static void setupPutTemplateRequestDeserializer(ObjectDeserializer op) { op.add(Builder::aliases, JsonpDeserializer.stringMapDeserializer(Alias._DESERIALIZER), "aliases"); + op.add(Builder::create, JsonpDeserializer.booleanDeserializer(), "create"); op.add(Builder::indexPatterns, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "index_patterns"); op.add(Builder::mappings, TypeMapping._DESERIALIZER, "mappings"); + op.add(Builder::name, JsonpDeserializer.stringDeserializer(), "name"); op.add(Builder::order, JsonpDeserializer.integerDeserializer(), "order"); op.add(Builder::settings, JsonpDeserializer.stringMapDeserializer(JsonData._DESERIALIZER), "settings"); op.add(Builder::version, JsonpDeserializer.longDeserializer(), "version"); diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/core/PutTemplateRequestTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/core/PutTemplateRequestTest.java new file mode 100644 index 0000000000..449b41e496 --- /dev/null +++ b/java-client/src/test/java/org/opensearch/client/opensearch/core/PutTemplateRequestTest.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.PutTemplateRequest; + +public class PutTemplateRequestTest 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, "order", 1); + + final String indexTemplate = new ObjectMapper().writeValueAsString(indexTemplateMap); + final var parser = mapper.jsonProvider().createParser(new StringReader(indexTemplate)); + + final PutTemplateRequest putTemplateRequest = PutTemplateRequest._DESERIALIZER.deserialize(parser, mapper); + + assertEquals(putTemplateRequest.name(), "test"); + assertEquals(putTemplateRequest.indexPatterns(), List.of("*")); + assertEquals((int) putTemplateRequest.order(), 1); + assertEquals(putTemplateRequest.create(), true); + } +}