Java/Kotlin SDK migration guide

The 9.0.0 release of Java and Kotlin SDKs unifies codebases in both SDKs. From now on, Java and Kotlin SDKs will be versioned and released together, and clients using both SDKs will get new features and bug fixes at the same time.

Although we tried to keep the API surface compatible with previous releases, you must make a few changes in your application code when migrating to the Java or Kotlin SDK in version 9.0.0.

Create the PubNub object

Instantiating the PubNub client through the constructor is no longer allowed. Use the PubNub.create() method instead.

PubNub pubnub = new PubNub(new PNConfiguration(...))

Async result callback

The signature of asynchronous API callbacks has changed. PNStatus is no longer provided or used in the async callback. The new Result type lets you access the successful result value or the underlying PubNubException in case of failure without worrying about potential null pointer exceptions or type mismatches.

The following sections show the legacy (< v.9.0.0) and new (= v.9.0.0) signatures and the proposed usage pattern for obtaining results from the API call.

Function signature

public void async(@NotNull final PNCallback<Output> callback)

public interface PNCallback<@Nullable X> {
void onResponse(@Nullable X result, @NotNull PNStatus status);
}

Usage pattern

pubnub.publish(...).async((result, status) -> {
if (status.isError()) {
// handle error either by looking at the exception, error or category:
status.getErrorData()
status.getCategory()
} else {
// handle success
System.out.println(
"Sent message with timetoken: " + result.getTimetoken()
);

}
});

Minor API differences

If, for some reason, you were depending on internal classes and methods in your application code, adjust your code as follows:

  • We removed the internal classes that should not be accessed from the compile classpath. That's why, avoid accessing or using these internal classes in your code.

  • All public classes are available in the com.pubnub.api package, while we moved internal ones to the dedicated com.pubnub.internal package. Don't access any of the internal classes in your code as they will be eventually removed.

  • If you used the Endpoint class in your Kotlin code, it previously took two type parameters: Endpoint<Input, Output>. As we have restricted access to the internal Input classes, the signature of this class changed to Endpoint<Output>.

If you notice that the changes affect any other Java or Kotlin SDK functionality, contact support to let us know.

Last updated on