All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.azure.communication.messages.models.NotificationContent Maven / Gradle / Ivy

The newest version!
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) TypeSpec Code Generator.
package com.azure.communication.messages.models;

import com.azure.core.annotation.Generated;
import com.azure.core.annotation.Immutable;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;
import java.util.List;

/**
 * Details of the message to send.
 */
@Immutable
public abstract class NotificationContent implements JsonSerializable {

    /*
     * The type discriminator describing a notification type.
     */
    @Generated
    private CommunicationMessageKind kind = CommunicationMessageKind.fromString("NotificationContent");

    /*
     * The Channel Registration ID for the Business Identifier.
     */
    @Generated
    private final String channelRegistrationId;

    /*
     * The native external platform user identifiers of the recipient.
     */
    @Generated
    private final List to;

    /**
     * Creates an instance of NotificationContent class.
     *
     * @param channelRegistrationId the channelRegistrationId value to set.
     * @param to the to value to set.
     */
    @Generated
    protected NotificationContent(String channelRegistrationId, List to) {
        this.channelRegistrationId = channelRegistrationId;
        this.to = to;
    }

    /**
     * Get the kind property: The type discriminator describing a notification type.
     *
     * @return the kind value.
     */
    @Generated
    public CommunicationMessageKind getKind() {
        return this.kind;
    }

    /**
     * Get the channelRegistrationId property: The Channel Registration ID for the Business Identifier.
     *
     * @return the channelRegistrationId value.
     */
    @Generated
    public String getChannelRegistrationId() {
        return this.channelRegistrationId;
    }

    /**
     * Get the to property: The native external platform user identifiers of the recipient.
     *
     * @return the to value.
     */
    @Generated
    public List getTo() {
        return this.to;
    }

    /**
     * {@inheritDoc}
     */
    @Generated
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("channelRegistrationId", this.channelRegistrationId);
        jsonWriter.writeArrayField("to", this.to, (writer, element) -> writer.writeString(element));
        jsonWriter.writeStringField("kind", this.kind == null ? null : this.kind.toString());
        return jsonWriter.writeEndObject();
    }

    /**
     * Reads an instance of NotificationContent from the JsonReader.
     *
     * @param jsonReader The JsonReader being read.
     * @return An instance of NotificationContent if the JsonReader was pointing to an instance of it, or null if it was
     * pointing to JSON null.
     * @throws IllegalStateException If the deserialized JSON object was missing any required properties.
     * @throws IOException If an error occurs while reading the NotificationContent.
     */
    @Generated
    public static NotificationContent fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            String discriminatorValue = null;
            try (JsonReader readerToUse = reader.bufferObject()) {
                // Prepare for reading
                readerToUse.nextToken();
                while (readerToUse.nextToken() != JsonToken.END_OBJECT) {
                    String fieldName = readerToUse.getFieldName();
                    readerToUse.nextToken();
                    if ("kind".equals(fieldName)) {
                        discriminatorValue = readerToUse.getString();
                        break;
                    } else {
                        readerToUse.skipChildren();
                    }
                }
                // Use the discriminator value to determine which subtype should be deserialized.
                if ("text".equals(discriminatorValue)) {
                    return TextNotificationContent.fromJson(readerToUse.reset());
                } else if ("image_v0".equals(discriminatorValue)) {
                    return MediaNotificationContent.fromJson(readerToUse.reset());
                } else if ("image".equals(discriminatorValue)) {
                    return ImageNotificationContent.fromJson(readerToUse.reset());
                } else if ("document".equals(discriminatorValue)) {
                    return DocumentNotificationContent.fromJson(readerToUse.reset());
                } else if ("video".equals(discriminatorValue)) {
                    return VideoNotificationContent.fromJson(readerToUse.reset());
                } else if ("audio".equals(discriminatorValue)) {
                    return AudioNotificationContent.fromJson(readerToUse.reset());
                } else if ("template".equals(discriminatorValue)) {
                    return TemplateNotificationContent.fromJson(readerToUse.reset());
                } else {
                    throw new IllegalStateException("Invalid Kind value - " + discriminatorValue);
                }
            }
        });
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy