SDK
SDK Java v3.x
2

This SDK is deprecated. We recommend to use the Kuzzle SDK-JVM.
A migration guide is available here

SDK JVM #

In this tutorial you will learn how to migrate from the Kuzzle Java SDK to the JVM SDK.

Having trouble? Get in touch with us on Discord!

Installation #

The installation of the JVM SDK is the same as for the Java SDK. You can find the SDK JARs directly on bintray. Download them and add them to your classpath.

Maven: #

from

Copied to clipboard!
<dependency>
  <groupId>io.kuzzle</groupId>
  <artifactId>kuzzle-sdk-java</artifactId>
  <version>3.0.0</version>
  <type>pom</type>
</dependency>

to

Copied to clipboard!
<dependency>
  <groupId>io.kuzzle</groupId>
  <artifactId>sdk-jvm</artifactId>
  <version>1.0.0</version>
  <type>pom</type>
</dependency>

Gradle: #

from

Copied to clipboard!
implementation 'io.kuzzle:kuzzle-sdk-java:3.0.0'

to

Copied to clipboard!
implementation 'io.kuzzle:sdk-jvm:1.0.0'

Ivy: #

from

Copied to clipboard!
<dependency org='io.kuzzle' name='kuzzle-sdk-java' rev='3.0.0'>
  <artifact name='kuzzle-sdk-java' ext='pom' ></artifact>
</dependency>

to

Copied to clipboard!
<dependency org='io.kuzzle' name='sdk-jvm' rev='1.0.0'>
  <artifact name='sdk-jvm' ext='pom' ></artifact>
</dependency>

Breaking changes #

Options handling #

The main difference between those two SDKs is the way they handle options on API actions.

In the Java SDK, there is an option class for each API action, such as SearchOptions, CreateOptions or SubscriptionOptions.

Using option objects was a simple and easy way for our SDK users to handle the many available options in API actions.

The new JVM SDK is now entirely written in Kotlin. The Java part of that SDK is now generated from the Kotlin code.
The idiomatic way of handling optional arguments in Kotlin is to use named arguments, which is not supported by Java.

What this means is this: optional arguments in Java are now handled using overloads. Most of them are automatically created when converting Kotlin code to Java, but we also added a few ones of our own, and removed less pertinent ones, so that the methods exposed by the Java SDK are as consistent as possible.

That is why in this SDK, we do not have any Options object.

For example:

Copied to clipboard!
public CompletableFuture<SearchResult> search(
      final String index,
      final String collection,
      final ConcurrentHashMap<String, Object> searchQuery,
      final SearchOptions options)

Becomes:

Copied to clipboard!
@JvmOverloads
fun search(
      index: String,
      collection: String,
      searchQuery: ConcurrentHashMap<String, Any?>,
      scroll: String? = null,
      size: Int? = null,
      from: Int = 0): CompletableFuture<SearchResult>

Which will generate the followings signatures:

Copied to clipboard!
public CompletableFuture<SearchResult> search(
      String index,
      String collection,
      ConcurrentHashMap<String, Object> searchQuery)

public CompletableFuture<SearchResult> search(
      String index,
      String collection,
      ConcurrentHashMap<String, Object> searchQuery,
      String scroll)

public CompletableFuture<SearchResult> search(
      String index,
      String collection,
      ConcurrentHashMap<String, Object> searchQuery,
      String scroll,
      Integer size)
      
public CompletableFuture<SearchResult> search(
      String index,
      String collection,
      ConcurrentHashMap<String, Object> searchQuery,
      Integer size,
      Integer from)

Example #

Using the Java SDK, you could have written:

Copied to clipboard!
SearchOptions options = new SearchOptions();
    options.setScroll("10s");
    options.setSize(5);

SearchResult results = kuzzle.getDocumentController().search(
  "nyc-open-data",
  "yellow-taxi",
  searchQuery, options).get();

With the new Jvm SDK it becomes:

Copied to clipboard!
SearchResult results = kuzzle.getDocumentController().search(
  "nyc-open-data",
  "yellow-taxi",
  searchQuery, "10s", 5).get();

You can find the full documentation of the Jvm SDK here, and compare signatures to adapt your code.