Java/Kotlin SDK 10.0.0 migration guide

The 10.0.0 release of Java and Kotlin SDKs is building upon the unified codebase of both SDKs. You can now use both SDKs within a single application.

Unified codebase release

Read the Java/Kotlin SDK v.9.0.0 migration guide for more information on migrating to v.9.0.0.

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

Most notable changes include:

  • Java SDK only: Changed package names for certain Java classes from com.pubnub.api.* to com.pubnub.api.java.* to allow you to use PubNub Kotlin and Java SDKs within a single application. You can use the provided migration script to help you change the names.

    PNConfiguration class in Java

    From version 10.0.0 of the Java SDK onward, the correct import for the PNConfiguration class is com.pubnub.api.java.v2.PNConfiguration.

  • Improved null safety in certain classes by introducing the PatchValue<T> type for optional fields that allows you to check whether its value has not been set or is null.

  • Removed mutable PNConfiguration classes which were deprecated in previous releases.

This guide provides an overview of all differences between the two versions and documents the steps you need to follow to migrate to Java/Kotlin SDK version 10.0.0.

Differences between 9.x.x and 10.0.0

For more details on specific APIs, refer to the Java and Kotlin SDK documentation.

See all the major differences between the two versions:

Feature/Method/FieldJava/Kotlin SDK 9.x.xJava/Kotlin SDK 10.x.x
PNChannelMetadata optional field typesString or AnyPatchValue<String> or PatchValue<Any>
PNUUIDMetadata optional field typesString or AnyPatchValue<String> or PatchValue<Any>
PNChannelMembership custom and status field typesMap<String, Any?> or String?PatchValue<Map<String, Any?>?>? or PatchValue<String?>?
PNMember custom and status field typesMap<String, Any?> or String?PatchValue<Map<String, Any?>?>? or PatchValue<String?>?
PNSetMembershipEvent custom and status field typesMap<String, Any?> or String?PatchValue<Map<String, Any?>?>? or PatchValue<String?>?
Mutable PNConfigurationcom.pubnub.api.PNConfigurationcom.pubnub.api.v2.PNConfiguration.builder(...)
Some Java package namescom.pubnub.api.*com.pubnub.api.java.*

Mutable PNConfiguration

Mutable PNConfiguration classes which were deprecated in previous releases have been removed. Use builders instead.

If you require changing values dynamically consider using value overrides.

Java SDK package names

We provide a script that scans all files with the .java and .kt extensions in the directory of your choice, and changes the package names of classes that have been moved to com.pubnub.api.java.* in PubNub Java SDK v. 10.0.0.

Package names

Not all classes have been moved, so we recommend that you use the provided migration script to change the package names.

When you run the script, a {filename}.bck backup of each changed file with is made, but you can disable this behavior.

Backup

The backups are made by the script as a best-effort. It is your responsibility to ensure no data is lost during the migration.

Download the script

You can download the script from GitHub.

Run the script

To run the script:

  1. Extract the contents of the downloaded .zip file to a directory of your choice, for example: update_script.

  2. Navigate to updated_script/bin/migration_utils and run the migration_utils file:

    migration_utils --dry-run --no-backups {path/to/your/Java/project}

    The script takes the following parameters:

    ParameterMandatoryDescription
    --dry-runOptionalRuns the script without changing any files. Instead, it prints a list of files that would be changed if the script was not run in dry run mode.
    --no-backupsOptionalDisables creating .bck backups for each changed file.
    -h, --helpOptionalDoesn't run the script and displays the documentation.
    {path/to/your/Java/project}YesMandatory positional argument that reflects the path to your Java project.

Example

If your Java project is located in the ~/projects/my_java_pubnub_project, you can run the script as follows:

migration_utils ~/projects/my_java_pubnub_project

Migration steps

To migrate from the Java/Kotlin SDK version 9.x.x to 10.0.0, upgrade the SDK version in your project, inspect the differences listed in the table above and change your code accordingly.

Last updated on