Typesense Java Client Okhttp Version Conflict
TLDR Ashish faced an error with Typesense Java okhttp version. Kishore Nallan helped identify the conflict with Spring Boot version, which updated okhttp to a compatible version.
Apr 11, 2023 (8 months ago)
Ashish
12:52 PMException in thread "main" java.lang.NoSuchMethodError: okhttp3.RequestBody.create(Ljava/lang/String;Lokhttp3/MediaType;)Lokhttp3/RequestBody;
at (ApiCall.java:134)
at org.typesense.api.Collections.create(Collections.java:16)
at com.pchf.audit.Test.main(Test.java:36)
Kishore Nallan
12:52 PM0.1.0
Kishore Nallan
12:52 PMAshish
12:54 PMAshish
12:57 PMKishore Nallan
01:06 PMAshish
01:14 PMAshish
01:14 PMpublic class Test {
public static void main(String[] args) {
List<Node> nodes = new ArrayList<>();
nodes.add(
new Node(
"https", // For Typesense Cloud use https
"", // For Typesense Cloud use
"443" // For Typesense Cloud use 443
)
);
Configuration configuration = new Configuration(nodes, Duration.ofSeconds(2),"xxxx");
Client client = new Client(configuration);
List<Field> fields = new ArrayList<>();
fields.add(new Field().name("countryName").type(FieldTypes.STRING));
fields.add(new Field().name("capital").type(FieldTypes.STRING));
fields.add(new Field().name("gdp").type(FieldTypes.INT32).facet(true).sort(true));
CollectionSchema collectionSchema = new CollectionSchema();
collectionSchema.name("Countries").fields(fields).defaultSortingField("gdp");
try {
client.collections().create(collectionSchema);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Ashish
01:18 PMAshish
01:18 PMException in thread "main" java.lang.NoSuchMethodError: okhttp3.RequestBody.create(Ljava/lang/String;Lokhttp3/MediaType;)Lokhttp3/RequestBody;
at (ApiCall.java:134)
at org.typesense.api.Collections.create(Collections.java:16)
at com.pchf.audit.Test.main(Test.java:36)
Kishore Nallan
01:18 PMKishore Nallan
01:19 PMKishore Nallan
01:19 PMAshish
01:20 PMKishore Nallan
01:21 PMAshish
01:21 PMAshish
01:22 PMAshish
01:22 PM[INFO] com.pchf:audit:jar:1.0-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter:jar:2.5.12:compile
[INFO] | +- org.springframework.boot:spring-boot:jar:2.5.12:compile
[INFO] | +- org.springframework.boot:spring-boot-autoconfigure:jar:2.5.12:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-logging:jar:2.5.12:compile
[INFO] | | +- ch.qos.logback:logback-classic:jar:1.2.11:compile
[INFO] | | | \- ch.qos.logback:logback-core:jar:1.2.11:compile
[INFO] | | +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.17.2:compile
[INFO] | | | \- org.apache.logging.log4j:log4j-api:jar:2.17.2:compile
[INFO] | | \- org.slf4j:jul-to-slf4j:jar:1.7.36:compile
[INFO] | +- jakarta.annotation:jakarta.annotation-api:jar:1.3.5:compile
[INFO] | \- org.springframework:spring-core:jar:5.3.18:compile
[INFO] | \- org.springframework:spring-jcl:jar:5.3.18:compile
[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:2.5.12:compile
[INFO] | +- org.springframework.boot:spring-boot-actuator-autoconfigure:jar:2.5.12:compile
[INFO] | | +- org.springframework.boot:spring-boot-actuator:jar:2.5.12:compile
[INFO] | | \- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.12.6:compile
[INFO] | \- io.micrometer:micrometer-core:jar:1.7.10:compile
[INFO] | +- org.hdrhistogram:HdrHistogram:jar:2.1.12:compile
[INFO] | \- org.latencyutils:LatencyUtils:jar:2.0.3:runtime
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.5.12:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-json:jar:2.5.12:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.12.6:compile
[INFO] | | \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.12.6:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.5.12:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.60:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-el:jar:9.0.60:compile
[INFO] | | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:9.0.60:compile
[INFO] | +- org.springframework:spring-web:jar:5.3.18:compile
[INFO] | \- org.springframework:spring-webmvc:jar:5.3.18:compile
[INFO] | \- org.springframework:spring-aop:jar:5.3.18:compile
[INFO] +- org.projectlombok:lombok:jar:1.18.24:provided
[INFO] +- org.springframework.data:spring-data-mongodb:jar:3.3.5:compile
[INFO] | +- org.springframework:spring-tx:jar:5.3.18:compile
[INFO] | +- org.springframework:spring-context:jar:5.3.18:compile
[INFO] | +- org.springframework:spring-beans:jar:5.3.18:compile
[INFO] | +- org.springframework:spring-expression:jar:5.3.18:compile
[INFO] | +- org.springframework.data:spring-data-commons:jar:2.5.10:compile
[INFO] | +- org.mongodb:mongodb-driver-core:jar:4.2.3:compile
[INFO] | | \- org.mongodb:bson:jar:4.2.3:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.36:compile
[INFO] +- org.springframework.kafka:spring-kafka:jar:2.7.12:compile
[INFO] | +- org.springframework:spring-messaging:jar:5.3.18:compile
[INFO] | +- org.springframework.retry:spring-retry:jar:1.3.2:compile
[INFO] | +- org.apache.kafka:kafka-clients:jar:2.7.2:compile
[INFO] | | +- com.github.luben:zstd-jni:jar:1.4.5-6:compile
[INFO] | | +- org.lz4:lz4-java:jar:1.7.1:compile
[INFO] | | \- org.xerial.snappy:snappy-java:jar:1.1.7.7:compile
[INFO] | \- com.google.code.findbugs:jsr305:jar:3.0.2:runtime
[INFO] +- org.typesense:typesense-java:jar:0.1.0:compile
[INFO] | +- javax.xml.bind:jaxb-api:jar:2.3.1:runtime
[INFO] | | \- javax.activation:javax.activation-api:jar:1.2.0:runtime
[INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.12.6.1:compile
[INFO] | | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.12.6:compile
[INFO] | | \- com.fasterxml.jackson.core:jackson-core:jar:2.12.6:compile
[INFO] | +- io.swagger.core.v3:swagger-annotations:jar:2.0.0:runtime
[INFO] | \- com.squareup.okhttp3:okhttp:jar:3.14.9:runtime
[INFO] | \- com.squareup.okio:okio:jar:1.17.2:runtime
[INFO] +- com.google.code.gson:gson:jar:2.6.2:compile
[INFO] \- junit:junit:jar:3.8.1:test
Ashish
01:23 PMKishore Nallan
01:23 PMimplementation "com.squareup.okhttp3:okhttp:4.9.1"
I wonder why the dep tree shows 3.x
Ashish
01:24 PMKishore Nallan
01:26 PM+--- org.typesense:typesense-java:0.1.0
| +--- javax.xml.bind:jaxb-api:2.3.1
| | \--- javax.activation:javax.activation-api:1.2.0
| +--- com.fasterxml.jackson.core:jackson-databind:2.14.1
| | +--- com.fasterxml.jackson.core:jackson-annotations:2.14.1
| | | \--- com.fasterxml.jackson:jackson-bom:2.14.1
| | | +--- com.fasterxml.jackson.core:jackson-annotations:2.14.1 (c)
| | | +--- com.fasterxml.jackson.core:jackson-core:2.14.1 (c)
| | | \--- com.fasterxml.jackson.core:jackson-databind:2.14.1 (c)
| | +--- com.fasterxml.jackson.core:jackson-core:2.14.1
| | | \--- com.fasterxml.jackson:jackson-bom:2.14.1 (*)
| | \--- com.fasterxml.jackson:jackson-bom:2.14.1 (*)
| +--- io.swagger.core.v3:swagger-annotations:2.0.0
| +--- org.slf4j:slf4j-api:2.0.5
| \--- com.squareup.okhttp3:okhttp:4.9.1
Ashish
01:27 PMKishore Nallan
01:28 PMKishore Nallan
01:28 PMAshish
01:30 PMAshish
01:33 PMKishore Nallan
01:34 PMKishore Nallan
01:35 PMAshish
01:38 PMAshish
01:40 PMKishore Nallan
01:41 PMKishore Nallan
01:42 PMApr 12, 2023 (8 months ago)
Ashish
06:23 AMAshish
06:23 AM <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.12</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
Ashish
06:23 AMAshish
06:23 AMAshish
06:24 AMAshish
06:24 AM<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=""
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 ">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.12</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.pchf</groupId>
<artifactId>audit</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>audit</name>
<properties>
<java.version>11</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>3.3.5</version>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.typesense</groupId>
<artifactId>typesense-java</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Kishore Nallan
06:37 AMTypesense
Indexed 3011 threads (79% resolved)
Similar Threads
UnrecognizedPropertyException in Java Client Search
Atul encountered an UnrecognizedPropertyException error using the Java client. Kishore Nallan suggested updating to the latest beta version, resolving the issue.
Resolving Duplicate Classes Error with Typesense and Kotlin
Matt faced "Duplicate class" errors in a Kotlin Android app after adding Typesense dependency. Kishore Nallan suggested excluding conflicting groups which resolved the issue.
Resolving Multilingual Search Function in Typesense Software
Bill is having difficulty with multilingual search functionality in Typesense software. Developer Kishore Nallan suggested setting a language locale and provided a demo build. The build solution had some issues, and after multiple rounds of software updates and troubleshooting, the problem still persists.
Resolving ClassNotFoundException in Android while using Typesense
Amal encountered a ClassNotFoundException while setting up Typesense in Android. Kishore Nallan recommended using Stack Overflow and Maven to resolve the issue. They also provided a fix for the Java client on Android, which worked for Amal.
Collaborative Work on the Java Client Project
Jason organizes a team to work on the Java client, asking Joe about his updates. Kartik shared his Github handle, while Joe is waiting for a Github password reset before sharing his work.