I'm just trying to solve the deprecation notes from my Java code of new firebase-admin SDK, the code is written in version 5.3.1 but after upgrading the version into 5.5.0 the deprecation notes appeared, here is a sample of my code:
Using FirebaseAuth (deprecatation on: Task, addOnSuccessListener and addOnFailureListener) :
private CompletableFuture<FirebaseToken> getDecryptedTokenCompletableFuture(String firebaseTokenString) {
CompletableFuture<FirebaseToken> tokenFuture = new CompletableFuture<>();
Task<FirebaseToken> tokenTask = FirebaseAuth.getInstance(firebaseApp).verifyIdToken(firebaseTokenString);
tokenTask.addOnSuccessListener(tokenFuture::complete);
tokenTask.addOnFailureListener(exception -> tokenFuture.completeExceptionally(new AuthorizationException("Failed to verify token", exception)));
return tokenFuture;
}
And for FirebaseDatabase (deprecatation on: Task, addOnSuccessListener, addOnFailureListener, updateChildren and removeValue) :
public static <T> CompletableFuture<T> toCompletableFuture(Task<T> task) {
CompletableFuture<T> future = new CompletableFuture<>();
task.addOnCompleteListener(result -> {
future.complete(result.getResult());
}).addOnFailureListener(future::completeExceptionally);
return future;
}
/**
* @param updatedParams if null it will removed child
* @param path path to update
* @return void when complete
*/
public CompletableFuture<Void> updateObjectData(Map<String, Object> updatedParams, String path) {
if (updatedParams == null) {
return removeObjectData(path);
}
logger.debug("Update ObjectData in firebase of ref ({}) with data: {}", path, updatedParams.toString());
DatabaseReference child = this.getUserDataReference().child(path);
return toCompletableFuture(child.updateChildren(updatedParams));
}
/**
* @param path path to of node to remove
* @return void when complete
*/
public CompletableFuture<Void> removeObjectData(String path) {
logger.debug("Remove ObjectData in firebase of ref ({})", path);
DatabaseReference child = this.getUserDataReference().child(path);
return toCompletableFuture(child.removeValue());
}
The deprecation note saying I have to use ApiFuture as what the release notes saying: https://firebase.google.com/support/release-notes/admin/java
And inside source, as for example:
/** * Similar to {@link #updateChildrenAsync(Map)} but returns a Task. * * @param update The paths to update and their new values * @return The {@link Task} for this operation. * @deprecated Use {@link #updateChildrenAsync(Map)} */
And
/** * Represents an asynchronous operation. * * @param <T> the type of the result of the operation * @deprecated {@code Task} has been deprecated in favor of * <a href="https://googleapis.github.io/api-common-java/1.1.0/apidocs/com/google/api/core/ApiFuture.html">{@code ApiFuture}</a>. * For every method x() that returns a {@code Task<T>}, you should be able to find a * corresponding xAsync() method that returns an {@code ApiFuture<T>}. */