Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PutTemplateRequest deserialization #723

Merged
merged 6 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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);
}
}
Loading