Search in sources :

Example 1 with JsonSerialiser

use of com.arm.mbed.cloud.sdk.common.JsonSerialiser in project mbed-cloud-sdk-java by ARMmbed.

the class Connect method notify.

/**
 * Allows a notification to be injected into the notifications system.
 * <p>
 * Example:
 *
 * <pre>
 * {@code
 * try {
 *       String deviceId = "015f4ac587f500000000000100100249";
 *       String resourcePath = "/3200/0/5501";
 *       String payload ="Q2hhbmdlIG1lIQ==";
 *       JSONSerialiser jsonSerialiser = new JSONSerialiser();
 *       String notifications = "{\"async-responses\":[{\"payload\":\"MQ\u003d\u003d\",\"id\":\"sfjasldfjl\"}],\"notifications\""
 *       +":[{\"path\":\"/3200/0/5501\",\"payload\":\"MQ\u003d\u003d\",\"ep\":\"015f4ac587f500000000000100100249\"}]}";
 *
 *       Resource resource = new Resource(deviceId, resourcePath);
 *       api.createResourceSubscriptionObserver(resource, BackpressureStrategy.BUFFER)
 *               .subscribe(new Consumer<Object>() {
 *
 *                   &#64;Override
 *                   public void accept(Object t) throws Exception {
 *                       log("Received notification value", t);
 *                   }
 *               });
 *       api.notify(jsonSerialiser, notifications);
 * } catch (MbedCloudException e) {
 *     e.printStackTrace();
 * }
 * }
 * </pre>
 *
 * @param deserialiser
 *            JSON deserialiser to use.
 * @param dataAsJson
 *            The notification data to inject as JSON String.
 */
@API
public void notify(@Nullable JsonSerialiser deserialiser, @Nullable String dataAsJson) {
    final JsonSerialiser jsonEngine = (deserialiser == null) ? new JsonSerialiser() : deserialiser;
    notify(jsonEngine.fromJson(dataAsJson, NotificationMessage.class));
}
Also used : JsonSerialiser(com.arm.mbed.cloud.sdk.common.JsonSerialiser) NotificationMessage(com.arm.mbed.cloud.sdk.internal.mds.model.NotificationMessage) API(com.arm.mbed.cloud.sdk.annotations.API)

Aggregations

API (com.arm.mbed.cloud.sdk.annotations.API)1 JsonSerialiser (com.arm.mbed.cloud.sdk.common.JsonSerialiser)1 NotificationMessage (com.arm.mbed.cloud.sdk.internal.mds.model.NotificationMessage)1