Skip to content

Commit

Permalink
Fix PutTemplateRequest deserialization (opensearch-project#723)
Browse files Browse the repository at this point in the history
* fix PutTemplateRequest deserialization

Signed-off-by: bfindlay <[email protected]>

* update changelog

Signed-off-by: bfindlay <[email protected]>

* fix changelog PR number

Signed-off-by: bfindlay <[email protected]>

* update for pr review

Signed-off-by: bfindlay <[email protected]>

* update unit test for pr

Signed-off-by: bfindlay <[email protected]>

* apply spotless check

Signed-off-by: bfindlay <[email protected]>

---------

Signed-off-by: bfindlay <[email protected]>
Signed-off-by: Vacha Shah <[email protected]>
  • Loading branch information
Bfindlay authored and VachaShah committed Feb 8, 2024
1 parent a4f3f9f commit be653a6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Removed

### Fixed
- Fix PutTemplateRequest field deserialization ([#723](https://github.com/opensearch-project/opensearch-java/pull/723))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,10 @@ public PutTemplateRequest build() {
protected static void setupPutTemplateRequestDeserializer(ObjectDeserializer<PutTemplateRequest.Builder> 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");
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.PutTemplateRequest;

public class PutTemplateRequestTest 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, "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);
}
}

0 comments on commit be653a6

Please sign in to comment.