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.*
tocom.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 iscom.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 isnull
. -
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/Field | Java/Kotlin SDK 9.x.x | Java/Kotlin SDK 10.x.x |
---|---|---|
PNChannelMetadata optional field types | String or Any | PatchValue<String> or PatchValue<Any> |
PNUUIDMetadata optional field types | String or Any | PatchValue<String> or PatchValue<Any> |
PNChannelMembership custom and status field types | Map<String, Any?> or String? | PatchValue<Map<String, Any?>?>? or PatchValue<String?>? |
PNMember custom and status field types | Map<String, Any?> or String? | PatchValue<Map<String, Any?>?>? or PatchValue<String?>? |
PNSetMembershipEvent custom and status field types | Map<String, Any?> or String? | PatchValue<Map<String, Any?>?>? or PatchValue<String?>? |
Mutable PNConfiguration | com.pubnub.api.PNConfiguration | com.pubnub.api.v2.PNConfiguration.builder(...) |
Some Java package names | com.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:
-
Extract the contents of the downloaded
.zip
file to a directory of your choice, for example:update_script
. -
Navigate to
updated_script/bin/migration_utils
and run themigration_utils
file:migration_utils --dry-run --no-backups {path/to/your/Java/project}
The script takes the following parameters:
Parameter Mandatory Description --dry-run
Optional Runs 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-backups
Optional Disables creating .bck
backups for each changed file.-h, --help
Optional Doesn't run the script and displays the documentation. {path/to/your/Java/project}
Yes Mandatory 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.