Skip to content

Commit

Permalink
Fix PutIndexTemplateRequest deserialization (#765) (#768)
Browse files Browse the repository at this point in the history
* Fix PutIndexTemplateRequest deserialization

Signed-off-by: Matthew Bogner <matt@ibogner.net>

* CHANGELOG.md

Signed-off-by: Matthew Bogner <matt@ibogner.net>

* spotless

Signed-off-by: Matthew Bogner <matt@ibogner.net>

---------

Signed-off-by: Matthew Bogner <matt@ibogner.net>
(cherry picked from commit d4aade4)
  • Loading branch information
matthewbogner authored Dec 12, 2023
1 parent 73be144 commit cd38878
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Fixed
- Fix partial success results for msearch_template ([#709](https://github.com/opensearch-project/opensearch-java/pull/709))
- Fix deserialization of node stats response ([#745](https://github.com/opensearch-project/opensearch-java/pull/745))
- Fix PutIndexTemplateRequest field deserialization ([#765](https://github.com/opensearch-project/opensearch-java/pull/765))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, Object> 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);
}

}

0 comments on commit cd38878

Please sign in to comment.