Skip to content

Commit

Permalink
Registered modules in SDKClient (opensearch-project#257)
Browse files Browse the repository at this point in the history
Signed-off-by: Owais Kazi <owaiskazi19@gmail.com>

Signed-off-by: Owais Kazi <owaiskazi19@gmail.com>
  • Loading branch information
owaiskazi19 authored Nov 25, 2022
1 parent a0a9c30 commit 4e17434
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ dependencies {
implementation("com.fasterxml.jackson.core:jackson-databind:${jacksonDatabindVersion}")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${jacksonDatabindVersion}")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${jacksonDatabindVersion}")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-guava:${jacksonDatabindVersion}")
testImplementation("org.junit.jupiter:junit-jupiter-api:${junit5Version}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junit5Version}")
testImplementation("org.opensearch.test:framework:${opensearchVersion}")
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/org/opensearch/sdk/SDKClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@

import java.io.IOException;

import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.datatype.guava.GuavaModule;
import org.apache.hc.core5.function.Factory;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.client5.http.ssl.NoopHostnameVerifier;
Expand Down Expand Up @@ -73,11 +77,15 @@ public TlsDetails create(final SSLEngine sslEngine) {

restClient = builder.build();

ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
mapper.registerModule(new GuavaModule());
mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.OBJECT_AND_NON_CONCRETE, JsonTypeInfo.As.PROPERTY);
mapper.configure(MapperFeature.USE_GETTERS_AS_SETTERS, false);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

// Create Client
OpenSearchTransport transport = new RestClientTransport(
restClient,
new JacksonJsonpMapper(new ObjectMapper().registerModule(new JavaTimeModule()))
);
OpenSearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper(mapper));
javaClient = new OpenSearchClient(transport);
return javaClient;
}
Expand Down

0 comments on commit 4e17434

Please sign in to comment.