From 9d4818112e1eb26d7559b335d138df008ef1562b Mon Sep 17 00:00:00 2001 From: anuchandy Date: Fri, 28 Jun 2024 14:37:31 -0700 Subject: [PATCH 1/7] Convert the handwritten models to azure-json --- .../models/AddChatParticipantsResult.java | 42 +++++++++- .../chat/models/ChatAttachment.java | 61 +++++++++++++- .../communication/chat/models/ChatError.java | 57 ++++++++++++- .../chat/models/ChatMessage.java | 81 ++++++++++++++++++- .../chat/models/ChatMessageContent.java | 62 +++++++++++++- .../chat/models/ChatMessageReadReceipt.java | 52 +++++++++++- .../chat/models/ChatParticipant.java | 53 +++++++++++- .../chat/models/ChatThreadItem.java | 77 ++++++++++++++++-- .../chat/models/ChatThreadProperties.java | 58 ++++++++++++- .../chat/models/CreateChatThreadResult.java | 44 +++++++++- .../chat/models/SendChatMessageOptions.java | 67 ++++++++++++--- .../chat/models/SendChatMessageResult.java | 46 ++++++++++- .../models/TypingNotificationOptions.java | 46 ++++++++++- .../chat/models/UpdateChatMessageOptions.java | 53 ++++++++++-- .../chat/models/UpdateChatThreadOptions.java | 46 ++++++++++- 15 files changed, 805 insertions(+), 40 deletions(-) diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/AddChatParticipantsResult.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/AddChatParticipantsResult.java index c1ccd17f51b8..6855523afed4 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/AddChatParticipantsResult.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/AddChatParticipantsResult.java @@ -5,14 +5,20 @@ package com.azure.communication.chat.models; 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 com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.IOException; import java.util.List; /** * Result of the add chat participants operation. */ @Immutable -public final class AddChatParticipantsResult { +public final class AddChatParticipantsResult implements JsonSerializable { /** * The participants that failed to be added to the chat thread. */ @@ -36,4 +42,38 @@ public AddChatParticipantsResult(List invalidParticipants) { public List getInvalidParticipants() { return this.invalidParticipants; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + // Not serializing 'invalidParticipants' as it is json read only. + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of AddChatParticipantsResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of AddChatParticipantsResult if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the AddChatParticipantsResult. + */ + public static AddChatParticipantsResult fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + List invalidParticipants = null; + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("invalidParticipants".equals(fieldName)) { + invalidParticipants = reader.readArray(ChatError::fromJson); + } else { + reader.skipChildren(); + } + } + return new AddChatParticipantsResult(invalidParticipants); + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatAttachment.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatAttachment.java index 1ee4e757a5ea..2948a639e17e 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatAttachment.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatAttachment.java @@ -4,12 +4,18 @@ package com.azure.communication.chat.models; import com.azure.core.annotation.Fluent; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; + +import java.io.IOException; /** * An attachment in a chat message. */ @Fluent -public final class ChatAttachment { +public final class ChatAttachment implements JsonSerializable { /** * Id of the attachment */ @@ -125,4 +131,57 @@ public ChatAttachment setPreviewUrl(String previewUrl) { this.previewUrl = previewUrl; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("id", id); + jsonWriter.writeStringField("attachmentType", attachmentType != null ? attachmentType.toString() : null); + jsonWriter.writeStringField("name", name); + jsonWriter.writeStringField("url", url); + jsonWriter.writeStringField("previewUrl", previewUrl); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatAttachment from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatAttachment if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the ChatAttachment. + */ + public static ChatAttachment fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + String id = null; + ChatAttachmentType attachmentType = null; + String name = null; + String url = null; + String previewUrl = null; + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("id".equals(fieldName)) { + id = reader.getString(); + } else if ("attachmentType".equals(fieldName)) { + attachmentType = ChatAttachmentType.fromString(reader.getString()); + } else if ("name".equals(fieldName)) { + name = reader.getString(); + } else if ("url".equals(fieldName)) { + url = reader.getString(); + } else if ("previewUrl".equals(fieldName)) { + previewUrl = reader.getString(); + } else { + reader.skipChildren(); + } + } + return new ChatAttachment(id, attachmentType) + .setName(name) + .setUrl(url) + .setPreviewUrl(previewUrl); + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatError.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatError.java index d6102cca462f..87f04e06be55 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatError.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatError.java @@ -4,13 +4,19 @@ package com.azure.communication.chat.models; import com.azure.core.annotation.Fluent; +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; /** * The Chat Services error. */ @Fluent -public final class ChatError { +public final class ChatError implements JsonSerializable { private final String code; @@ -83,4 +89,53 @@ public ChatError getInnerError() { return this.innerError; } + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("code", code); + jsonWriter.writeStringField("message", message); + jsonWriter.writeStringField("target", target); + jsonWriter.writeArrayField("details", details, (writer, error) -> error.toJson(writer)); + jsonWriter.writeJsonField("innerError", innerError); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatError from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatError if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the ChatError. + */ + public static ChatError fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + String code = null; + String message = null; + String target = null; + List details = null; + ChatError innerError = null; + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("code".equals(fieldName)) { + code = reader.getString(); + } else if ("message".equals(fieldName)) { + message = reader.getString(); + } else if ("target".equals(fieldName)) { + target = reader.getString(); + } else if ("details".equals(fieldName)) { + details = reader.readArray(ChatError::fromJson); + } else if ("innerError".equals(fieldName)) { + innerError = ChatError.fromJson(reader); + } else { + reader.skipChildren(); + } + } + return new ChatError(message, code, target, details, innerError); + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessage.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessage.java index bda1ef5edf7e..a81319013703 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessage.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessage.java @@ -5,7 +5,14 @@ import com.azure.communication.common.CommunicationIdentifier; import com.azure.core.annotation.Fluent; +import com.azure.core.util.CoreUtils; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.IOException; import java.time.OffsetDateTime; import java.util.Map; @@ -13,7 +20,7 @@ * The ChatMessage model. */ @Fluent -public final class ChatMessage { +public final class ChatMessage implements JsonSerializable { /** * The id of the chat message. */ @@ -297,4 +304,76 @@ public ChatMessage setMetadata(Map metadata) { this.metadata = metadata; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("id", id); + jsonWriter.writeStringField("type", type != null ? type.toString() : null); + jsonWriter.writeJsonField("content", content); + jsonWriter.writeStringField("senderDisplayName", senderDisplayName); + jsonWriter.writeStringField("createdOn", createdOn != null ? createdOn.toString() : null); + // final CommunicationIdentifierModel identifier = CommunicationIdentifierConverter.convert(sender); + // jsonWriter.writeJsonField("senderCommunicationIdentifier", identifier); + jsonWriter.writeStringField("deletedOn", deletedOn != null ? deletedOn.toString() : null); + jsonWriter.writeStringField("editedOn", editedOn != null ? editedOn.toString() : null); + jsonWriter.writeMapField("metadata", metadata, JsonWriter::writeString); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of SendChatMessageOptions from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of SendChatMessageOptions if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the SendChatMessageOptions. + */ + public static ChatMessage fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + final ChatMessage message = new ChatMessage(); + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("id".equals(fieldName)) { + message.setId(reader.getString()); + } else if ("type".equals(fieldName)) { + message.setType(ChatMessageType.fromString(reader.getString())); + } else if ("version".equals(fieldName)) { + message.setVersion(reader.getString()); + } else if ("content".equals(fieldName)) { + message.setContent(ChatMessageContent.fromJson(reader)); + } else if ("senderDisplayName".equals(fieldName)) { + message.setSenderDisplayName(reader.getString()); + } else if ("createdOn".equals(fieldName)) { + final String value = reader.getString(); + if (!CoreUtils.isNullOrEmpty(value)) { + message.setCreatedOn(OffsetDateTime.parse(value)); + } + // } else if ("senderCommunicationIdentifier".equals(fieldName)) { + // TODO (anu) : uncomment this after generating protocol layer + // final CommunicationIdentifierModel identifier = reader.readObject(CommunicationIdentifierModel::fromJson); + // receipt.setSender(CommunicationIdentifierConverter.convert(identifier)); + } else if ("deletedOn".equals(fieldName)) { + final String value = reader.getString(); + if (!CoreUtils.isNullOrEmpty(value)) { + message.setDeletedOn(OffsetDateTime.parse(value)); + } + } else if ("editedOn".equals(fieldName)) { + final String value = reader.getString(); + if (!CoreUtils.isNullOrEmpty(value)) { + message.setEditedOn(OffsetDateTime.parse(value)); + } + } else if ("metadata".equals(fieldName)) { + message.setMetadata(reader.readMap(JsonReader::getString)); + } else { + reader.skipChildren(); + } + } + return message; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageContent.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageContent.java index a5b5320755df..24aa9d27408e 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageContent.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageContent.java @@ -5,13 +5,20 @@ import com.azure.communication.common.CommunicationIdentifier; import com.azure.core.annotation.Fluent; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.IOException; +import java.util.List; + /** * Content of a chat message. */ @Fluent -public final class ChatMessageContent { +public final class ChatMessageContent implements JsonSerializable { @JsonProperty(value = "message") private String message; @@ -106,4 +113,57 @@ public CommunicationIdentifier getInitiator() { return this.initiator; } + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("message", message); + jsonWriter.writeStringField("topic", topic); + jsonWriter.writeArrayField("participants", participants, (writer, participant) -> participant.toJson(writer)); + jsonWriter.writeArrayField("attachments", attachments, (writer, attachment) -> attachment.toJson(writer)); + // final CommunicationIdentifierModel identifier = CommunicationIdentifierConverter.convert(initiator); + // jsonWriter.writeJsonField("initiatorCommunicationIdentifier", identifier); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatMessageContent from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatMessageContent if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the ChatMessageContent. + */ + public static ChatMessageContent fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + String message = null; + String topic = null; + List participants = null; + List attachments = null; + CommunicationIdentifier initiator = null; + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("message".equals(fieldName)) { + message = reader.getString(); + } else if ("topic".equals(fieldName)) { + topic = reader.getString(); + } else if ("participants".equals(fieldName)) { + participants = reader.readArray(ChatParticipant::fromJson); + } else if ("attachments".equals(fieldName)) { + attachments = reader.readArray(ChatAttachment::fromJson); + // } else if ("initiatorCommunicationIdentifier".equals(fieldName)) { + // TODO (anu) : uncomment this after generating protocol layer + // final CommunicationIdentifierModel identifier = reader.readObject(CommunicationIdentifierModel::fromJson); + // initiator = CommunicationIdentifierConverter.convert(identifier); + } else { + reader.skipChildren(); + } + } + return new ChatMessageContent(message, topic, participants, initiator) + .setAttachments(attachments); + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageReadReceipt.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageReadReceipt.java index da7a9028e507..c341496281d5 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageReadReceipt.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageReadReceipt.java @@ -5,14 +5,21 @@ import com.azure.communication.common.CommunicationIdentifier; import com.azure.core.annotation.Fluent; +import com.azure.core.util.CoreUtils; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.IOException; import java.time.OffsetDateTime; /** * The ChatMessageReadReceipt model. */ @Fluent -public final class ChatMessageReadReceipt { +public final class ChatMessageReadReceipt implements JsonSerializable { /** * Identifies a participant in Azure Communication services. A participant * is, for example, a phone number or an Azure communication user. This @@ -99,4 +106,47 @@ public ChatMessageReadReceipt setReadOn(OffsetDateTime readOn) { this.readOn = readOn; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + // Not serializing any properties, all are json read only. + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of AddChatParticipantsResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of AddChatParticipantsResult if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the AddChatParticipantsResult. + */ + public static ChatMessageReadReceipt fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + final ChatMessageReadReceipt receipt = new ChatMessageReadReceipt(); + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + // if ("senderCommunicationIdentifier".equals(fieldName)) { + // TODO (anu) : uncomment this after generating protocol layer + // final CommunicationIdentifierModel identifier = reader.readObject(CommunicationIdentifierModel::fromJson); + // receipt.setSender(CommunicationIdentifierConverter.convert(identifier)); + if ("chatMessageId".equals(fieldName)) { + receipt.setChatMessageId(reader.getString()); + } else if ("readOn".equals(fieldName)) { + final String value = reader.getString(); + if (!CoreUtils.isNullOrEmpty(value)) { + receipt.setReadOn(OffsetDateTime.parse(value)); + } + } else { + reader.skipChildren(); + } + } + return receipt; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatParticipant.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatParticipant.java index 1912de23b5b9..00e0f5766e83 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatParticipant.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatParticipant.java @@ -5,14 +5,21 @@ import com.azure.communication.common.CommunicationIdentifier; import com.azure.core.annotation.Fluent; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.IOException; import java.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; /** * The ChatParticipant model. */ @Fluent -public final class ChatParticipant { +public final class ChatParticipant implements JsonSerializable { /** * Identifies a participant in Azure Communication services. A participant * is, for example, a phone number or an Azure communication user. This @@ -100,4 +107,48 @@ public ChatParticipant setShareHistoryTime(OffsetDateTime shareHistoryTime) { this.shareHistoryTime = shareHistoryTime; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + // TODO (anu) : uncomment this after generating protocol layer + // final CommunicationIdentifierModel identifier = CommunicationIdentifierConverter.convert(communicationIdentifier); + // jsonWriter.writeJsonField("communicationIdentifier", identifier); + jsonWriter.writeStringField("displayName", displayName); + jsonWriter.writeStringField("startDateTime", shareHistoryTime.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ParticipantsUpdated from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ParticipantsUpdated if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the ParticipantsUpdated. + */ + public static ChatParticipant fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + final ChatParticipant participant = new ChatParticipant(); + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + // if ("communicationIdentifier".equals(fieldName)) { + // TODO (anu) : uncomment this after generating protocol layer + // final CommunicationIdentifierModel identifier = reader.readObject(CommunicationIdentifierModel::fromJson); + // participant.communicationIdentifier = CommunicationIdentifierConverter.convert(identifier); + if ("displayName".equals(fieldName)) { + participant.displayName = reader.getString(); + } else if ("startDateTime".equals(fieldName)) { + participant.shareHistoryTime = OffsetDateTime.parse(reader.getString(), DateTimeFormatter.ISO_OFFSET_DATE_TIME); + } else { + reader.skipChildren(); + } + } + return participant; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadItem.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadItem.java index cb1d2e941513..be1c40026645 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadItem.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadItem.java @@ -5,14 +5,21 @@ package com.azure.communication.chat.models; import com.azure.core.annotation.Fluent; +import com.azure.core.util.CoreUtils; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.IOException; import java.time.OffsetDateTime; /** * Summary information of a chat thread. */ @Fluent -public final class ChatThreadItem { +public final class ChatThreadItem implements JsonSerializable { /* * Chat thread id. */ @@ -46,7 +53,7 @@ public ChatThreadItem() { /** * Get the id property: Chat thread id. - * + * * @return the id value. */ public String getId() { @@ -55,7 +62,7 @@ public String getId() { /** * Set the id property: Chat thread id. - * + * * @param id the id value to set. * @return the ChatThreadItem object itself. */ @@ -66,7 +73,7 @@ public ChatThreadItem setId(String id) { /** * Get the topic property: Chat thread topic. - * + * * @return the topic value. */ public String getTopic() { @@ -75,7 +82,7 @@ public String getTopic() { /** * Set the topic property: Chat thread topic. - * + * * @param topic the topic value to set. * @return the ChatThreadItem object itself. */ @@ -87,7 +94,7 @@ public ChatThreadItem setTopic(String topic) { /** * Get the deletedOn property: The timestamp when the chat thread was deleted. The timestamp is in RFC3339 format: * `yyyy-MM-ddTHH:mm:ssZ`. - * + * * @return the deletedOn value. */ public OffsetDateTime getDeletedOn() { @@ -97,7 +104,7 @@ public OffsetDateTime getDeletedOn() { /** * Set the deletedOn property: The timestamp when the chat thread was deleted. The timestamp is in RFC3339 format: * `yyyy-MM-ddTHH:mm:ssZ`. - * + * * @param deletedOn the deletedOn value to set. * @return the ChatThreadItem object itself. */ @@ -109,10 +116,64 @@ public ChatThreadItem setDeletedOn(OffsetDateTime deletedOn) { /** * Get the lastMessageReceivedOn property: The timestamp when the last message arrived at the server. The timestamp * is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. - * + * * @return the lastMessageReceivedOn value. */ public OffsetDateTime getLastMessageReceivedOn() { return this.lastMessageReceivedOn; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("id", id); + jsonWriter.writeStringField("topic", topic); + jsonWriter.writeStringField("deletedOn", deletedOn != null ? deletedOn.toString() : null); + // Not writing 'lastMessageReceivedOn' property as it's json ready only. + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatThreadItem from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatThreadItem if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the ChatThreadItem. + */ + public static ChatThreadItem fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + final ChatThreadItem item = new ChatThreadItem(); + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("id".equals(fieldName)) { + item.setId(reader.getString()); + } else if ("topic".equals(fieldName)) { + item.setTopic(reader.getString()); + } else if ("deletedOn".equals(fieldName)) { + final String value = reader.getString(); + if (!CoreUtils.isNullOrEmpty(value)) { + item.setDeletedOn(OffsetDateTime.parse(value)); + } + } else if ("lastMessageReceivedOn".equals(fieldName)) { + final String value = reader.getString(); + if (!CoreUtils.isNullOrEmpty(value)) { + item.setLastMessageReceivedOn(OffsetDateTime.parse(value)); + } + } else { + reader.skipChildren(); + } + } + return item; + }); + } + + private ChatThreadItem setLastMessageReceivedOn(OffsetDateTime lastMessageReceivedOn) { + this.lastMessageReceivedOn = lastMessageReceivedOn; + return this; + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadProperties.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadProperties.java index c8f6b513fa85..8f24aeaa0f65 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadProperties.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadProperties.java @@ -5,14 +5,20 @@ import com.azure.communication.common.CommunicationIdentifier; import com.azure.core.annotation.Fluent; +import com.azure.core.util.CoreUtils; +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.time.OffsetDateTime; /** * The ChatThread model. */ @Fluent -public final class ChatThreadProperties { +public final class ChatThreadProperties implements JsonSerializable { private String id; @@ -107,4 +113,54 @@ public ChatThreadProperties setCreatedBy(CommunicationIdentifier createdBy) { this.createdBy = createdBy; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("id", id); + jsonWriter.writeStringField("topic", topic); + jsonWriter.writeStringField("createdOn", createdOn != null ? createdOn.toString() : null); + // TODO (anu) : uncomment this after generating protocol layer + // final CommunicationIdentifierModel identifier = CommunicationIdentifierConverter.convert(createdBy); + // jsonWriter.writeJsonField("createdBy", identifier); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatThreadProperties from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatThreadProperties if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the ChatThreadProperties. + */ + public static ChatThreadProperties fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + final ChatThreadProperties properties = new ChatThreadProperties(); + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("id".equals(fieldName)) { + properties.setId(reader.getString()); + } else if ("topic".equals(fieldName)) { + properties.setTopic(reader.getString()); + } else if ("createdOn".equals(fieldName)) { + final String value = reader.getString(); + if (!CoreUtils.isNullOrEmpty(value)) { + properties.setCreatedOn(OffsetDateTime.parse(value)); + } + // } else if ("createdBy".equals(fieldName)) { + // TODO (anu) : uncomment this after generating protocol layer + // final CommunicationIdentifierModel identifier = reader.readObject(CommunicationIdentifierModel::fromJson); + // properties.setCreatedBy(CommunicationIdentifierConverter.convert(identifier)); + } else { + reader.skipChildren(); + } + } + return properties; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/CreateChatThreadResult.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/CreateChatThreadResult.java index df3dbdb3c4a9..05bf2d1fe6eb 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/CreateChatThreadResult.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/CreateChatThreadResult.java @@ -4,15 +4,20 @@ package com.azure.communication.chat.models; import com.azure.core.annotation.Fluent; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.IOException; import java.util.List; /** * The CreateChatThreadResult model. */ @Fluent -public final class CreateChatThreadResult { +public final class CreateChatThreadResult implements JsonSerializable { /** * The thread property. */ @@ -54,4 +59,41 @@ public List getInvalidParticipants() { return this.invalidParticipants; } + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeJsonField("chatThread", chatThreadProperties); + // Not serializing 'invalidParticipants' as it is json read only. + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of AddChatParticipantsResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of AddChatParticipantsResult if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the AddChatParticipantsResult. + */ + public static CreateChatThreadResult fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ChatThreadProperties chatThreadProperties = null; + List invalidParticipants = null; + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("chatThread".equals(fieldName)) { + chatThreadProperties = ChatThreadProperties.fromJson(reader); + } else if ("invalidParticipants".equals(fieldName)) { + invalidParticipants = reader.readArray(ChatError::fromJson); + } else { + reader.skipChildren(); + } + } + return new CreateChatThreadResult(chatThreadProperties, invalidParticipants); + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageOptions.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageOptions.java index 8790c6c1173d..e6d07cd78e9f 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageOptions.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageOptions.java @@ -5,14 +5,20 @@ package com.azure.communication.chat.models; import com.azure.core.annotation.Fluent; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.IOException; import java.util.Map; /** * Details of the message to send. */ @Fluent -public final class SendChatMessageOptions { +public final class SendChatMessageOptions implements JsonSerializable { /* * Chat message content. */ @@ -46,7 +52,7 @@ public SendChatMessageOptions() { /** * Get the content property: Chat message content. - * + * * @return the content value. */ public String getContent() { @@ -55,7 +61,7 @@ public String getContent() { /** * Set the content property: Chat message content. - * + * * @param content the content value to set. * @return the SendChatMessageOptions object itself. */ @@ -67,7 +73,7 @@ public SendChatMessageOptions setContent(String content) { /** * Get the senderDisplayName property: The display name of the chat message sender. This property is used to * populate sender name for push notifications. - * + * * @return the senderDisplayName value. */ public String getSenderDisplayName() { @@ -77,7 +83,7 @@ public String getSenderDisplayName() { /** * Set the senderDisplayName property: The display name of the chat message sender. This property is used to * populate sender name for push notifications. - * + * * @param senderDisplayName the senderDisplayName value to set. * @return the SendChatMessageOptions object itself. */ @@ -88,7 +94,7 @@ public SendChatMessageOptions setSenderDisplayName(String senderDisplayName) { /** * Get the type property: The chat message type. - * + * * @return the type value. */ public ChatMessageType getType() { @@ -97,7 +103,7 @@ public ChatMessageType getType() { /** * Set the type property: The chat message type. - * + * * @param type the type value to set. * @return the SendChatMessageOptions object itself. */ @@ -108,7 +114,7 @@ public SendChatMessageOptions setType(ChatMessageType type) { /** * Get the metadata property: Message metadata. - * + * * @return the metadata value. */ public Map getMetadata() { @@ -117,7 +123,7 @@ public Map getMetadata() { /** * Set the metadata property: Message metadata. - * + * * @param metadata the metadata value to set. * @return the SendChatMessageOptions object itself. */ @@ -125,4 +131,47 @@ public SendChatMessageOptions setMetadata(Map metadata) { this.metadata = metadata; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("content", content); + jsonWriter.writeStringField("senderDisplayName", senderDisplayName); + jsonWriter.writeStringField("type", type != null ? type.toString() : null); + jsonWriter.writeMapField("metadata", metadata, JsonWriter::writeString); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of SendChatMessageOptions from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of SendChatMessageOptions if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the SendChatMessageOptions. + */ + public static SendChatMessageOptions fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + final SendChatMessageOptions options = new SendChatMessageOptions(); + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("content".equals(fieldName)) { + options.setContent(reader.getString()); + } else if ("senderDisplayName".equals(fieldName)) { + options.setSenderDisplayName(reader.getString()); + } else if ("type".equals(fieldName)) { + options.setType(ChatMessageType.fromString(reader.getString())); + } else if ("metadata".equals(fieldName)) { + options.setMetadata(reader.readMap(JsonReader::getString)); + } else { + reader.skipChildren(); + } + } + return options; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageResult.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageResult.java index b8f4503fc996..e3d7375bbb10 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageResult.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageResult.java @@ -5,13 +5,19 @@ package com.azure.communication.chat.models; import com.azure.core.annotation.Fluent; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.IOException; + /** * Result of the send message operation. */ @Fluent -public final class SendChatMessageResult { +public final class SendChatMessageResult implements JsonSerializable { /* * A server-generated message id. */ @@ -26,7 +32,7 @@ public SendChatMessageResult() { /** * Get the id property: A server-generated message id. - * + * * @return the id value. */ public String getId() { @@ -35,7 +41,7 @@ public String getId() { /** * Set the id property: A server-generated message id. - * + * * @param id the id value to set. * @return the SendChatMessageResult object itself. */ @@ -43,4 +49,38 @@ public SendChatMessageResult setId(String id) { this.id = id; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("id", id); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of SendChatMessageResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of SendChatMessageResult if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the SendChatMessageResult. + */ + public static SendChatMessageResult fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + SendChatMessageResult result = new SendChatMessageResult(); + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("id".equals(fieldName)) { + result.setId(reader.getString()); + } else { + reader.skipChildren(); + } + } + return result; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/TypingNotificationOptions.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/TypingNotificationOptions.java index 81a733ec31ec..4193b0aa6694 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/TypingNotificationOptions.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/TypingNotificationOptions.java @@ -5,13 +5,19 @@ package com.azure.communication.chat.models; import com.azure.core.annotation.Fluent; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.IOException; + /** * Request payload for typing notifications. */ @Fluent -public final class TypingNotificationOptions { +public final class TypingNotificationOptions implements JsonSerializable { /* * The display name of the typing notification sender. This property is used to populate sender name for push * notifications. @@ -28,7 +34,7 @@ public TypingNotificationOptions() { /** * Get the senderDisplayName property: The display name of the typing notification sender. This property is used to * populate sender name for push notifications. - * + * * @return the senderDisplayName value. */ public String getSenderDisplayName() { @@ -38,7 +44,7 @@ public String getSenderDisplayName() { /** * Set the senderDisplayName property: The display name of the typing notification sender. This property is used to * populate sender name for push notifications. - * + * * @param senderDisplayName the senderDisplayName value to set. * @return the TypingNotificationOptions object itself. */ @@ -46,4 +52,38 @@ public TypingNotificationOptions setSenderDisplayName(String senderDisplayName) this.senderDisplayName = senderDisplayName; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("senderDisplayName", senderDisplayName); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of TypingNotificationOptions from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of TypingNotificationOptions if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the TypingNotificationOptions. + */ + public static TypingNotificationOptions fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + TypingNotificationOptions options = new TypingNotificationOptions(); + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("senderDisplayName".equals(fieldName)) { + options.setSenderDisplayName(reader.getString()); + } else { + reader.skipChildren(); + } + } + return options; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/UpdateChatMessageOptions.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/UpdateChatMessageOptions.java index 191309e34575..3371981fcdf7 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/UpdateChatMessageOptions.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/UpdateChatMessageOptions.java @@ -5,14 +5,20 @@ package com.azure.communication.chat.models; import com.azure.core.annotation.Fluent; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; import com.fasterxml.jackson.annotation.JsonProperty; + +import java.io.IOException; import java.util.Map; /** * Request payload for updating a chat message. */ @Fluent -public final class UpdateChatMessageOptions { +public final class UpdateChatMessageOptions implements JsonSerializable { /* * Chat message content. */ @@ -33,7 +39,7 @@ public UpdateChatMessageOptions() { /** * Get the content property: Chat message content. - * + * * @return the content value. */ public String getContent() { @@ -42,7 +48,7 @@ public String getContent() { /** * Set the content property: Chat message content. - * + * * @param content the content value to set. * @return the UpdateChatMessageOptions object itself. */ @@ -53,7 +59,7 @@ public UpdateChatMessageOptions setContent(String content) { /** * Get the metadata property: Message metadata. - * + * * @return the metadata value. */ public Map getMetadata() { @@ -62,7 +68,7 @@ public Map getMetadata() { /** * Set the metadata property: Message metadata. - * + * * @param metadata the metadata value to set. * @return the UpdateChatMessageOptions object itself. */ @@ -70,4 +76,41 @@ public UpdateChatMessageOptions setMetadata(Map metadata) { this.metadata = metadata; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("content", content); + jsonWriter.writeMapField("metadata", metadata, JsonWriter::writeString); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of SendChatMessageOptions from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of SendChatMessageOptions if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the SendChatMessageOptions. + */ + public static SendChatMessageOptions fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + final SendChatMessageOptions options = new SendChatMessageOptions(); + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("content".equals(fieldName)) { + options.setContent(reader.getString()); + } else if ("metadata".equals(fieldName)) { + options.setMetadata(reader.readMap(JsonReader::getString)); + } else { + reader.skipChildren(); + } + } + return options; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/UpdateChatThreadOptions.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/UpdateChatThreadOptions.java index 505d6f6bbcdb..9b40c8375f11 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/UpdateChatThreadOptions.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/UpdateChatThreadOptions.java @@ -5,13 +5,19 @@ package com.azure.communication.chat.models; import com.azure.core.annotation.Fluent; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.IOException; + /** * Request payload for updating a chat thread. */ @Fluent -public final class UpdateChatThreadOptions { +public final class UpdateChatThreadOptions implements JsonSerializable { /* * Chat thread topic. */ @@ -26,7 +32,7 @@ public UpdateChatThreadOptions() { /** * Get the topic property: Chat thread topic. - * + * * @return the topic value. */ public String getTopic() { @@ -35,7 +41,7 @@ public String getTopic() { /** * Set the topic property: Chat thread topic. - * + * * @param topic the topic value to set. * @return the UpdateChatThreadOptions object itself. */ @@ -43,4 +49,38 @@ public UpdateChatThreadOptions setTopic(String topic) { this.topic = topic; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("topic", topic); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of SendChatMessageResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of SendChatMessageResult if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the SendChatMessageResult. + */ + public static UpdateChatThreadOptions fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + UpdateChatThreadOptions options = new UpdateChatThreadOptions(); + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("topic".equals(fieldName)) { + options.setTopic(reader.getString()); + } else { + reader.skipChildren(); + } + } + return options; + }); + } } From e5ac733b6216145cb5caca5f49207c523274d6cc Mon Sep 17 00:00:00 2001 From: anuchandy Date: Fri, 28 Jun 2024 14:58:03 -0700 Subject: [PATCH 2/7] regenerate the protocol layer for azure-json --- ...reCommunicationChatServiceImplBuilder.java | 37 +++++- .../chat/implementation/ChatsImpl.java | 106 ++++------------ .../models/AddChatParticipantsOptions.java | 47 ++++++- .../models/AddChatParticipantsResult.java | 46 ++++++- .../implementation/models/ChatAttachment.java | 63 ++++++++-- .../models/ChatAttachmentType.java | 2 - .../implementation/models/ChatMessage.java | 119 +++++++++++++----- .../models/ChatMessageContent.java | 82 +++++++++--- .../models/ChatMessageReadReceipt.java | 70 +++++++++-- .../ChatMessageReadReceiptsCollection.java | 56 ++++++++- .../models/ChatMessagesCollection.java | 50 +++++++- .../models/ChatParticipant.java | 86 ++++++++++--- .../models/ChatParticipantsCollection.java | 50 +++++++- .../implementation/models/ChatThreadItem.java | 77 ++++++++++-- .../models/ChatThreadProperties.java | 80 +++++++++--- .../models/ChatThreadsItemCollection.java | 53 +++++++- .../CommunicationCloudEnvironmentModel.java | 2 - .../models/CommunicationError.java | 61 +++++++-- .../models/CommunicationErrorResponse.java | 46 ++++++- .../models/CommunicationIdentifierModel.java | 69 ++++++++-- .../CommunicationIdentifierModelKind.java | 2 - .../CommunicationUserIdentifierModel.java | 47 ++++++- .../models/CreateChatThreadOptions.java | 51 +++++++- .../models/CreateChatThreadResult.java | 50 +++++++- .../models/IndividualStatusResponse.java | 52 +++++++- .../MicrosoftTeamsAppIdentifierModel.java | 52 +++++++- .../MicrosoftTeamsUserIdentifierModel.java | 57 ++++++++- .../models/MultiStatusResponse.java | 43 ++++++- .../models/PhoneNumberIdentifierModel.java | 46 ++++++- .../models/SendReadReceiptRequest.java | 46 ++++++- .../chat/models/ChatMessageType.java | 2 - .../chat/models/ChatThreadItem.java | 69 +++++----- .../chat/models/SendChatMessageOptions.java | 57 ++++----- .../chat/models/SendChatMessageResult.java | 26 ++-- .../models/TypingNotificationOptions.java | 28 ++--- .../chat/models/UpdateChatMessageOptions.java | 41 +++--- .../chat/models/UpdateChatThreadOptions.java | 29 +++-- .../swagger/README.md | 2 +- 38 files changed, 1480 insertions(+), 422 deletions(-) diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/AzureCommunicationChatServiceImplBuilder.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/AzureCommunicationChatServiceImplBuilder.java index abed72eb84d0..2fa0a2c5241a 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/AzureCommunicationChatServiceImplBuilder.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/AzureCommunicationChatServiceImplBuilder.java @@ -6,9 +6,11 @@ import com.azure.core.annotation.Generated; import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.client.traits.AzureKeyCredentialTrait; import com.azure.core.client.traits.ConfigurationTrait; import com.azure.core.client.traits.EndpointTrait; import com.azure.core.client.traits.HttpTrait; +import com.azure.core.credential.AzureKeyCredential; import com.azure.core.http.HttpClient; import com.azure.core.http.HttpHeaderName; import com.azure.core.http.HttpHeaders; @@ -18,8 +20,9 @@ import com.azure.core.http.policy.AddDatePolicy; import com.azure.core.http.policy.AddHeadersFromContextPolicy; import com.azure.core.http.policy.AddHeadersPolicy; -import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.http.policy.AzureKeyCredentialPolicy; import com.azure.core.http.policy.HttpLoggingPolicy; +import com.azure.core.http.policy.HttpLogOptions; import com.azure.core.http.policy.HttpPipelinePolicy; import com.azure.core.http.policy.HttpPolicyProviders; import com.azure.core.http.policy.RequestIdPolicy; @@ -44,6 +47,7 @@ @ServiceClientBuilder(serviceClients = { AzureCommunicationChatServiceImpl.class }) public final class AzureCommunicationChatServiceImplBuilder implements HttpTrait, ConfigurationTrait, + AzureKeyCredentialTrait, EndpointTrait { @Generated private static final String SDK_NAME = "name"; @@ -172,6 +176,22 @@ public AzureCommunicationChatServiceImplBuilder configuration(Configuration conf return this; } + /* + * The AzureKeyCredential used for authentication. + */ + @Generated + private AzureKeyCredential azureKeyCredential; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public AzureCommunicationChatServiceImplBuilder credential(AzureKeyCredential azureKeyCredential) { + this.azureKeyCredential = azureKeyCredential; + return this; + } + /* * The service endpoint */ @@ -277,17 +297,24 @@ private HttpPipeline createHttpPipeline() { if (headers.getSize() > 0) { policies.add(new AddHeadersPolicy(headers)); } - this.pipelinePolicies.stream().filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) .forEach(p -> policies.add(p)); HttpPolicyProviders.addBeforeRetryPolicies(policies); policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, new RetryPolicy())); policies.add(new AddDatePolicy()); - this.pipelinePolicies.stream().filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) + if (azureKeyCredential != null) { + policies.add(new AzureKeyCredentialPolicy("Authorization", azureKeyCredential)); + } + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) .forEach(p -> policies.add(p)); HttpPolicyProviders.addAfterRetryPolicies(policies); - policies.add(new HttpLoggingPolicy(httpLogOptions)); + policies.add(new HttpLoggingPolicy(localHttpLogOptions)); HttpPipeline httpPipeline = new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0])) - .httpClient(httpClient).clientOptions(localClientOptions).build(); + .httpClient(httpClient) + .clientOptions(localClientOptions) + .build(); return httpPipeline; } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/ChatsImpl.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/ChatsImpl.java index 5a70e42baa2c..4ed905418c24 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/ChatsImpl.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/ChatsImpl.java @@ -30,8 +30,10 @@ import com.azure.core.http.rest.Response; import com.azure.core.http.rest.RestProxy; import com.azure.core.util.Context; +import com.azure.core.util.DateTimeRfc1123; import com.azure.core.util.FluxUtil; import java.time.OffsetDateTime; +import java.util.UUID; import reactor.core.publisher.Mono; /** @@ -59,8 +61,8 @@ public final class ChatsImpl { } /** - * The interface defining all the services for AzureCommunicationChatServiceChats to be used by the proxy service - * to perform REST calls. + * The interface defining all the services for AzureCommunicationChatServiceChats to be used by the proxy service to + * perform REST calls. */ @Host("{endpoint}") @ServiceInterface(name = "AzureCommunicationCh") @@ -72,7 +74,6 @@ public interface ChatsService { code = { 401, 403, 429, 503 }) @UnexpectedResponseExceptionType(CommunicationErrorResponseException.class) Mono> createChatThread(@HostParam("endpoint") String endpoint, - @HeaderParam("repeatability-request-id") String repeatabilityRequestId, @QueryParam("api-version") String apiVersion, @BodyParam("application/json") CreateChatThreadOptions createChatThreadRequest, @HeaderParam("Accept") String accept, Context context); @@ -112,11 +113,6 @@ Mono> listChatThreadsNext( * Creates a chat thread. * * @param createChatThreadRequest Request payload for creating a chat thread. - * @param repeatabilityRequestId If specified, the client directs that the request is repeatable; that is, that the - * client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate - * response without the server executing the request multiple times. The value of the Repeatability-Request-Id is an - * opaque string representing a client-generated, globally unique for all time, identifier for the request. It is - * recommended to use version 4 (random) UUIDs. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. * @throws CommunicationErrorResponseException thrown if the request is rejected by server on status code 401, 403, @@ -126,22 +122,19 @@ Mono> listChatThreadsNext( * {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> createChatThreadWithResponseAsync( - CreateChatThreadOptions createChatThreadRequest, String repeatabilityRequestId) { + public Mono> + createChatThreadWithResponseAsync(CreateChatThreadOptions createChatThreadRequest) { final String accept = "application/json"; + String repeatabilityRequestId = UUID.randomUUID().toString(); + String repeatabilityFirstSent = DateTimeRfc1123.toRfc1123String(OffsetDateTime.now()); return FluxUtil.withContext(context -> service.createChatThread(this.client.getEndpoint(), - repeatabilityRequestId, this.client.getApiVersion(), createChatThreadRequest, accept, context)); + this.client.getApiVersion(), createChatThreadRequest, accept, context)); } /** * Creates a chat thread. * * @param createChatThreadRequest Request payload for creating a chat thread. - * @param repeatabilityRequestId If specified, the client directs that the request is repeatable; that is, that the - * client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate - * response without the server executing the request multiple times. The value of the Repeatability-Request-Id is an - * opaque string representing a client-generated, globally unique for all time, identifier for the request. It is - * recommended to use version 4 (random) UUIDs. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. @@ -152,34 +145,13 @@ public Mono> createChatThreadWithResponseAsync( * {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> createChatThreadWithResponseAsync( - CreateChatThreadOptions createChatThreadRequest, String repeatabilityRequestId, Context context) { + public Mono> + createChatThreadWithResponseAsync(CreateChatThreadOptions createChatThreadRequest, Context context) { final String accept = "application/json"; - return service.createChatThread(this.client.getEndpoint(), repeatabilityRequestId, this.client.getApiVersion(), - createChatThreadRequest, accept, context); - } - - /** - * Creates a chat thread. - * - * @param createChatThreadRequest Request payload for creating a chat thread. - * @param repeatabilityRequestId If specified, the client directs that the request is repeatable; that is, that the - * client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate - * response without the server executing the request multiple times. The value of the Repeatability-Request-Id is an - * opaque string representing a client-generated, globally unique for all time, identifier for the request. It is - * recommended to use version 4 (random) UUIDs. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server on status code 401, 403, - * 429, 503. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return result of the create chat thread operation on successful completion of {@link Mono}. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono createChatThreadAsync(CreateChatThreadOptions createChatThreadRequest, - String repeatabilityRequestId) { - return createChatThreadWithResponseAsync(createChatThreadRequest, repeatabilityRequestId) - .flatMap(res -> Mono.justOrEmpty(res.getValue())); + String repeatabilityRequestId = UUID.randomUUID().toString(); + String repeatabilityFirstSent = DateTimeRfc1123.toRfc1123String(OffsetDateTime.now()); + return service.createChatThread(this.client.getEndpoint(), this.client.getApiVersion(), createChatThreadRequest, + accept, context); } /** @@ -195,8 +167,7 @@ public Mono createChatThreadAsync(CreateChatThreadOption */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono createChatThreadAsync(CreateChatThreadOptions createChatThreadRequest) { - final String repeatabilityRequestId = null; - return createChatThreadWithResponseAsync(createChatThreadRequest, repeatabilityRequestId) + return createChatThreadWithResponseAsync(createChatThreadRequest) .flatMap(res -> Mono.justOrEmpty(res.getValue())); } @@ -204,11 +175,6 @@ public Mono createChatThreadAsync(CreateChatThreadOption * Creates a chat thread. * * @param createChatThreadRequest Request payload for creating a chat thread. - * @param repeatabilityRequestId If specified, the client directs that the request is repeatable; that is, that the - * client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate - * response without the server executing the request multiple times. The value of the Repeatability-Request-Id is an - * opaque string representing a client-generated, globally unique for all time, identifier for the request. It is - * recommended to use version 4 (random) UUIDs. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. @@ -219,8 +185,8 @@ public Mono createChatThreadAsync(CreateChatThreadOption */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono createChatThreadAsync(CreateChatThreadOptions createChatThreadRequest, - String repeatabilityRequestId, Context context) { - return createChatThreadWithResponseAsync(createChatThreadRequest, repeatabilityRequestId, context) + Context context) { + return createChatThreadWithResponseAsync(createChatThreadRequest, context) .flatMap(res -> Mono.justOrEmpty(res.getValue())); } @@ -228,11 +194,6 @@ public Mono createChatThreadAsync(CreateChatThreadOption * Creates a chat thread. * * @param createChatThreadRequest Request payload for creating a chat thread. - * @param repeatabilityRequestId If specified, the client directs that the request is repeatable; that is, that the - * client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate - * response without the server executing the request multiple times. The value of the Repeatability-Request-Id is an - * opaque string representing a client-generated, globally unique for all time, identifier for the request. It is - * recommended to use version 4 (random) UUIDs. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. @@ -242,31 +203,9 @@ public Mono createChatThreadAsync(CreateChatThreadOption * @return result of the create chat thread operation along with {@link Response}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response createChatThreadWithResponse( - CreateChatThreadOptions createChatThreadRequest, String repeatabilityRequestId, Context context) { - return createChatThreadWithResponseAsync(createChatThreadRequest, repeatabilityRequestId, context).block(); - } - - /** - * Creates a chat thread. - * - * @param createChatThreadRequest Request payload for creating a chat thread. - * @param repeatabilityRequestId If specified, the client directs that the request is repeatable; that is, that the - * client can make the request multiple times with the same Repeatability-Request-Id and get back an appropriate - * response without the server executing the request multiple times. The value of the Repeatability-Request-Id is an - * opaque string representing a client-generated, globally unique for all time, identifier for the request. It is - * recommended to use version 4 (random) UUIDs. - * @throws IllegalArgumentException thrown if parameters fail the validation. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server. - * @throws CommunicationErrorResponseException thrown if the request is rejected by server on status code 401, 403, - * 429, 503. - * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return result of the create chat thread operation. - */ - @ServiceMethod(returns = ReturnType.SINGLE) - public CreateChatThreadResult createChatThread(CreateChatThreadOptions createChatThreadRequest, - String repeatabilityRequestId) { - return createChatThreadWithResponse(createChatThreadRequest, repeatabilityRequestId, Context.NONE).getValue(); + public Response + createChatThreadWithResponse(CreateChatThreadOptions createChatThreadRequest, Context context) { + return createChatThreadWithResponseAsync(createChatThreadRequest, context).block(); } /** @@ -282,8 +221,7 @@ public CreateChatThreadResult createChatThread(CreateChatThreadOptions createCha */ @ServiceMethod(returns = ReturnType.SINGLE) public CreateChatThreadResult createChatThread(CreateChatThreadOptions createChatThreadRequest) { - final String repeatabilityRequestId = null; - return createChatThreadWithResponse(createChatThreadRequest, repeatabilityRequestId, Context.NONE).getValue(); + return createChatThreadWithResponse(createChatThreadRequest, Context.NONE).getValue(); } /** diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/AddChatParticipantsOptions.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/AddChatParticipantsOptions.java index cd1037a86632..1f0000208599 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/AddChatParticipantsOptions.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/AddChatParticipantsOptions.java @@ -5,18 +5,21 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +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; /** * Participants to be added to the thread. */ @Fluent -public final class AddChatParticipantsOptions { +public final class AddChatParticipantsOptions implements JsonSerializable { /* * Participants to add to a chat thread. */ - @JsonProperty(value = "participants", required = true) private List participants; /** @@ -44,4 +47,42 @@ public AddChatParticipantsOptions setParticipants(List particip this.participants = participants; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeArrayField("participants", this.participants, (writer, element) -> writer.writeJson(element)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of AddChatParticipantsOptions from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of AddChatParticipantsOptions 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 AddChatParticipantsOptions. + */ + public static AddChatParticipantsOptions fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + AddChatParticipantsOptions deserializedAddChatParticipantsOptions = new AddChatParticipantsOptions(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("participants".equals(fieldName)) { + List participants = reader.readArray(reader1 -> ChatParticipant.fromJson(reader1)); + deserializedAddChatParticipantsOptions.participants = participants; + } else { + reader.skipChildren(); + } + } + + return deserializedAddChatParticipantsOptions; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/AddChatParticipantsResult.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/AddChatParticipantsResult.java index 760b63e132b5..fe4e966e0135 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/AddChatParticipantsResult.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/AddChatParticipantsResult.java @@ -5,18 +5,21 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Immutable; -import com.fasterxml.jackson.annotation.JsonProperty; +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; /** * Result of the add chat participants operation. */ @Immutable -public final class AddChatParticipantsResult { +public final class AddChatParticipantsResult implements JsonSerializable { /* * The participants that failed to be added to the chat thread. */ - @JsonProperty(value = "invalidParticipants", access = JsonProperty.Access.WRITE_ONLY) private List invalidParticipants; /** @@ -33,4 +36,41 @@ public AddChatParticipantsResult() { public List getInvalidParticipants() { return this.invalidParticipants; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of AddChatParticipantsResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of AddChatParticipantsResult if the JsonReader was pointing to an instance of it, or null if + * it was pointing to JSON null. + * @throws IOException If an error occurs while reading the AddChatParticipantsResult. + */ + public static AddChatParticipantsResult fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + AddChatParticipantsResult deserializedAddChatParticipantsResult = new AddChatParticipantsResult(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("invalidParticipants".equals(fieldName)) { + List invalidParticipants + = reader.readArray(reader1 -> CommunicationError.fromJson(reader1)); + deserializedAddChatParticipantsResult.invalidParticipants = invalidParticipants; + } else { + reader.skipChildren(); + } + } + + return deserializedAddChatParticipantsResult; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatAttachment.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatAttachment.java index bccb27edd8c0..7d1215fb5d1f 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatAttachment.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatAttachment.java @@ -5,41 +5,40 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; /** * An attachment in a chat message. */ @Fluent -public final class ChatAttachment { +public final class ChatAttachment implements JsonSerializable { /* * Id of the attachment */ - @JsonProperty(value = "id", required = true) private String id; /* * The type of attachment. */ - @JsonProperty(value = "attachmentType", required = true) private ChatAttachmentType attachmentType; /* * The name of the attachment content. */ - @JsonProperty(value = "name") private String name; /* * The URL where the attachment can be downloaded */ - @JsonProperty(value = "url") private String url; /* * The URL where the preview of attachment can be downloaded */ - @JsonProperty(value = "previewUrl") private String previewUrl; /** @@ -147,4 +146,54 @@ public ChatAttachment setPreviewUrl(String previewUrl) { this.previewUrl = previewUrl; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("id", this.id); + jsonWriter.writeStringField("attachmentType", + this.attachmentType == null ? null : this.attachmentType.toString()); + jsonWriter.writeStringField("name", this.name); + jsonWriter.writeStringField("url", this.url); + jsonWriter.writeStringField("previewUrl", this.previewUrl); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatAttachment from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatAttachment 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 ChatAttachment. + */ + public static ChatAttachment fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ChatAttachment deserializedChatAttachment = new ChatAttachment(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("id".equals(fieldName)) { + deserializedChatAttachment.id = reader.getString(); + } else if ("attachmentType".equals(fieldName)) { + deserializedChatAttachment.attachmentType = ChatAttachmentType.fromString(reader.getString()); + } else if ("name".equals(fieldName)) { + deserializedChatAttachment.name = reader.getString(); + } else if ("url".equals(fieldName)) { + deserializedChatAttachment.url = reader.getString(); + } else if ("previewUrl".equals(fieldName)) { + deserializedChatAttachment.previewUrl = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedChatAttachment; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatAttachmentType.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatAttachmentType.java index 1c6a344e8271..2c39b51b1b26 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatAttachmentType.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatAttachmentType.java @@ -5,7 +5,6 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.util.ExpandableStringEnum; -import com.fasterxml.jackson.annotation.JsonCreator; import java.util.Collection; /** @@ -37,7 +36,6 @@ public ChatAttachmentType() { * @param name a name to look for. * @return the corresponding ChatAttachmentType. */ - @JsonCreator public static ChatAttachmentType fromString(String name) { return fromString(name, ChatAttachmentType.class); } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessage.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessage.java index 06e480dde532..2a75b82c97f6 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessage.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessage.java @@ -6,85 +6,73 @@ import com.azure.communication.chat.models.ChatMessageType; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +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.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; import java.util.Map; /** * Chat message. */ @Fluent -public final class ChatMessage { +public final class ChatMessage implements JsonSerializable { /* * The id of the chat message. This id is server generated. */ - @JsonProperty(value = "id", required = true) private String id; /* * The chat message type. */ - @JsonProperty(value = "type", required = true) private ChatMessageType type; /* * Sequence of the chat message in the conversation. */ - @JsonProperty(value = "sequenceId", required = true) private String sequenceId; /* * Version of the chat message. */ - @JsonProperty(value = "version", required = true) private String version; /* * Content of a chat message. */ - @JsonProperty(value = "content") private ChatMessageContent content; /* - * The display name of the chat message sender. This property is used to populate sender name for push - * notifications. + * The display name of the chat message sender. This property is used to populate sender name for push notifications. */ - @JsonProperty(value = "senderDisplayName") private String senderDisplayName; /* - * The timestamp when the chat message arrived at the server. The timestamp is in RFC3339 format: - * `yyyy-MM-ddTHH:mm:ssZ`. + * The timestamp when the chat message arrived at the server. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "createdOn", required = true) private OffsetDateTime createdOn; /* - * Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an - * Azure communication user. This model is polymorphic: Apart from kind and rawId, at most one further property may - * be set which must match the kind enum value. + * Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from kind and rawId, at most one further property may be set which must match the kind enum value. */ - @JsonProperty(value = "senderCommunicationIdentifier") private CommunicationIdentifierModel senderCommunicationIdentifier; /* - * The timestamp (if applicable) when the message was deleted. The timestamp is in RFC3339 format: - * `yyyy-MM-ddTHH:mm:ssZ`. + * The timestamp (if applicable) when the message was deleted. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "deletedOn") private OffsetDateTime deletedOn; /* - * The last timestamp (if applicable) when the message was edited. The timestamp is in RFC3339 format: - * `yyyy-MM-ddTHH:mm:ssZ`. + * The last timestamp (if applicable) when the message was edited. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "editedOn") private OffsetDateTime editedOn; /* * Message metadata. */ - @JsonProperty(value = "metadata") private Map metadata; /** @@ -239,8 +227,8 @@ public ChatMessage setCreatedOn(OffsetDateTime createdOn) { /** * Get the senderCommunicationIdentifier property: Identifies a participant in Azure Communication services. A - * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart - * from kind and rawId, at most one further property may be set which must match the kind enum value. + * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from + * kind and rawId, at most one further property may be set which must match the kind enum value. * * @return the senderCommunicationIdentifier value. */ @@ -250,8 +238,8 @@ public CommunicationIdentifierModel getSenderCommunicationIdentifier() { /** * Set the senderCommunicationIdentifier property: Identifies a participant in Azure Communication services. A - * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart - * from kind and rawId, at most one further property may be set which must match the kind enum value. + * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from + * kind and rawId, at most one further property may be set which must match the kind enum value. * * @param senderCommunicationIdentifier the senderCommunicationIdentifier value to set. * @return the ChatMessage object itself. @@ -324,4 +312,79 @@ public ChatMessage setMetadata(Map metadata) { this.metadata = metadata; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("id", this.id); + jsonWriter.writeStringField("type", this.type == null ? null : this.type.toString()); + jsonWriter.writeStringField("sequenceId", this.sequenceId); + jsonWriter.writeStringField("version", this.version); + jsonWriter.writeStringField("createdOn", + this.createdOn == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.createdOn)); + jsonWriter.writeJsonField("content", this.content); + jsonWriter.writeStringField("senderDisplayName", this.senderDisplayName); + jsonWriter.writeJsonField("senderCommunicationIdentifier", this.senderCommunicationIdentifier); + jsonWriter.writeStringField("deletedOn", + this.deletedOn == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.deletedOn)); + jsonWriter.writeStringField("editedOn", + this.editedOn == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.editedOn)); + jsonWriter.writeMapField("metadata", this.metadata, (writer, element) -> writer.writeString(element)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatMessage from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatMessage 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 ChatMessage. + */ + public static ChatMessage fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ChatMessage deserializedChatMessage = new ChatMessage(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("id".equals(fieldName)) { + deserializedChatMessage.id = reader.getString(); + } else if ("type".equals(fieldName)) { + deserializedChatMessage.type = ChatMessageType.fromString(reader.getString()); + } else if ("sequenceId".equals(fieldName)) { + deserializedChatMessage.sequenceId = reader.getString(); + } else if ("version".equals(fieldName)) { + deserializedChatMessage.version = reader.getString(); + } else if ("createdOn".equals(fieldName)) { + deserializedChatMessage.createdOn + = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); + } else if ("content".equals(fieldName)) { + deserializedChatMessage.content = ChatMessageContent.fromJson(reader); + } else if ("senderDisplayName".equals(fieldName)) { + deserializedChatMessage.senderDisplayName = reader.getString(); + } else if ("senderCommunicationIdentifier".equals(fieldName)) { + deserializedChatMessage.senderCommunicationIdentifier + = CommunicationIdentifierModel.fromJson(reader); + } else if ("deletedOn".equals(fieldName)) { + deserializedChatMessage.deletedOn + = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); + } else if ("editedOn".equals(fieldName)) { + deserializedChatMessage.editedOn + = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); + } else if ("metadata".equals(fieldName)) { + Map metadata = reader.readMap(reader1 -> reader1.getString()); + deserializedChatMessage.metadata = metadata; + } else { + reader.skipChildren(); + } + } + + return deserializedChatMessage; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageContent.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageContent.java index 0ce005db9fc4..938c5cd9bf13 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageContent.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageContent.java @@ -5,44 +5,41 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +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; /** * Content of a chat message. */ @Fluent -public final class ChatMessageContent { +public final class ChatMessageContent implements JsonSerializable { /* * Chat message content for messages of types text or html. */ - @JsonProperty(value = "message") private String message; /* * Chat message content for messages of type topicUpdated. */ - @JsonProperty(value = "topic") private String topic; /* * Chat message content for messages of types participantAdded or participantRemoved. */ - @JsonProperty(value = "participants") private List participants; /* * List of attachments for this message */ - @JsonProperty(value = "attachments") private List attachments; /* - * Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an - * Azure communication user. This model is polymorphic: Apart from kind and rawId, at most one further property may - * be set which must match the kind enum value. + * Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from kind and rawId, at most one further property may be set which must match the kind enum value. */ - @JsonProperty(value = "initiatorCommunicationIdentifier") private CommunicationIdentifierModel initiatorCommunicationIdentifier; /** @@ -92,8 +89,7 @@ public ChatMessageContent setTopic(String topic) { } /** - * Get the participants property: Chat message content for messages of types participantAdded or - * participantRemoved. + * Get the participants property: Chat message content for messages of types participantAdded or participantRemoved. * * @return the participants value. */ @@ -102,8 +98,7 @@ public List getParticipants() { } /** - * Set the participants property: Chat message content for messages of types participantAdded or - * participantRemoved. + * Set the participants property: Chat message content for messages of types participantAdded or participantRemoved. * * @param participants the participants value to set. * @return the ChatMessageContent object itself. @@ -135,8 +130,8 @@ public ChatMessageContent setAttachments(List attachments) { /** * Get the initiatorCommunicationIdentifier property: Identifies a participant in Azure Communication services. A - * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart - * from kind and rawId, at most one further property may be set which must match the kind enum value. + * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from + * kind and rawId, at most one further property may be set which must match the kind enum value. * * @return the initiatorCommunicationIdentifier value. */ @@ -146,8 +141,8 @@ public CommunicationIdentifierModel getInitiatorCommunicationIdentifier() { /** * Set the initiatorCommunicationIdentifier property: Identifies a participant in Azure Communication services. A - * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart - * from kind and rawId, at most one further property may be set which must match the kind enum value. + * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from + * kind and rawId, at most one further property may be set which must match the kind enum value. * * @param initiatorCommunicationIdentifier the initiatorCommunicationIdentifier value to set. * @return the ChatMessageContent object itself. @@ -157,4 +152,55 @@ public CommunicationIdentifierModel getInitiatorCommunicationIdentifier() { this.initiatorCommunicationIdentifier = initiatorCommunicationIdentifier; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("message", this.message); + jsonWriter.writeStringField("topic", this.topic); + jsonWriter.writeArrayField("participants", this.participants, (writer, element) -> writer.writeJson(element)); + jsonWriter.writeArrayField("attachments", this.attachments, (writer, element) -> writer.writeJson(element)); + jsonWriter.writeJsonField("initiatorCommunicationIdentifier", this.initiatorCommunicationIdentifier); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatMessageContent from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatMessageContent if the JsonReader was pointing to an instance of it, or null if it was + * pointing to JSON null. + * @throws IOException If an error occurs while reading the ChatMessageContent. + */ + public static ChatMessageContent fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ChatMessageContent deserializedChatMessageContent = new ChatMessageContent(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("message".equals(fieldName)) { + deserializedChatMessageContent.message = reader.getString(); + } else if ("topic".equals(fieldName)) { + deserializedChatMessageContent.topic = reader.getString(); + } else if ("participants".equals(fieldName)) { + List participants = reader.readArray(reader1 -> ChatParticipant.fromJson(reader1)); + deserializedChatMessageContent.participants = participants; + } else if ("attachments".equals(fieldName)) { + List attachments = reader.readArray(reader1 -> ChatAttachment.fromJson(reader1)); + deserializedChatMessageContent.attachments = attachments; + } else if ("initiatorCommunicationIdentifier".equals(fieldName)) { + deserializedChatMessageContent.initiatorCommunicationIdentifier + = CommunicationIdentifierModel.fromJson(reader); + } else { + reader.skipChildren(); + } + } + + return deserializedChatMessageContent; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageReadReceipt.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageReadReceipt.java index a2ee436fe6f3..2000e9026e19 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageReadReceipt.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageReadReceipt.java @@ -5,32 +5,32 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +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.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; /** * A chat message read receipt indicates the time a chat message was read by a recipient. */ @Fluent -public final class ChatMessageReadReceipt { +public final class ChatMessageReadReceipt implements JsonSerializable { /* - * Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an - * Azure communication user. This model is polymorphic: Apart from kind and rawId, at most one further property may - * be set which must match the kind enum value. + * Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from kind and rawId, at most one further property may be set which must match the kind enum value. */ - @JsonProperty(value = "senderCommunicationIdentifier", required = true) private CommunicationIdentifierModel senderCommunicationIdentifier; /* * Id of the chat message that has been read. This id is generated by the server. */ - @JsonProperty(value = "chatMessageId", required = true) private String chatMessageId; /* * The time at which the message was read. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "readOn", required = true) private OffsetDateTime readOn; /** @@ -41,8 +41,8 @@ public ChatMessageReadReceipt() { /** * Get the senderCommunicationIdentifier property: Identifies a participant in Azure Communication services. A - * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart - * from kind and rawId, at most one further property may be set which must match the kind enum value. + * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from + * kind and rawId, at most one further property may be set which must match the kind enum value. * * @return the senderCommunicationIdentifier value. */ @@ -52,8 +52,8 @@ public CommunicationIdentifierModel getSenderCommunicationIdentifier() { /** * Set the senderCommunicationIdentifier property: Identifies a participant in Azure Communication services. A - * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart - * from kind and rawId, at most one further property may be set which must match the kind enum value. + * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from + * kind and rawId, at most one further property may be set which must match the kind enum value. * * @param senderCommunicationIdentifier the senderCommunicationIdentifier value to set. * @return the ChatMessageReadReceipt object itself. @@ -105,4 +105,50 @@ public ChatMessageReadReceipt setReadOn(OffsetDateTime readOn) { this.readOn = readOn; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeJsonField("senderCommunicationIdentifier", this.senderCommunicationIdentifier); + jsonWriter.writeStringField("chatMessageId", this.chatMessageId); + jsonWriter.writeStringField("readOn", + this.readOn == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.readOn)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatMessageReadReceipt from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatMessageReadReceipt 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 ChatMessageReadReceipt. + */ + public static ChatMessageReadReceipt fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ChatMessageReadReceipt deserializedChatMessageReadReceipt = new ChatMessageReadReceipt(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("senderCommunicationIdentifier".equals(fieldName)) { + deserializedChatMessageReadReceipt.senderCommunicationIdentifier + = CommunicationIdentifierModel.fromJson(reader); + } else if ("chatMessageId".equals(fieldName)) { + deserializedChatMessageReadReceipt.chatMessageId = reader.getString(); + } else if ("readOn".equals(fieldName)) { + deserializedChatMessageReadReceipt.readOn + = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); + } else { + reader.skipChildren(); + } + } + + return deserializedChatMessageReadReceipt; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageReadReceiptsCollection.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageReadReceiptsCollection.java index 77452f5f5f01..480439f93ac2 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageReadReceiptsCollection.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageReadReceiptsCollection.java @@ -5,24 +5,26 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +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; /** * A paged collection of chat message read receipts. */ @Fluent -public final class ChatMessageReadReceiptsCollection { +public final class ChatMessageReadReceiptsCollection implements JsonSerializable { /* * Collection of chat message read receipts. */ - @JsonProperty(value = "value", required = true) private List value; /* * If there are more chat message read receipts that can be retrieved, the next link will be populated. */ - @JsonProperty(value = "nextLink", access = JsonProperty.Access.WRITE_ONLY) private String nextLink; /** @@ -52,12 +54,54 @@ public ChatMessageReadReceiptsCollection setValue(List v } /** - * Get the nextLink property: If there are more chat message read receipts that can be retrieved, the next link - * will be populated. + * Get the nextLink property: If there are more chat message read receipts that can be retrieved, the next link will + * be populated. * * @return the nextLink value. */ public String getNextLink() { return this.nextLink; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeArrayField("value", this.value, (writer, element) -> writer.writeJson(element)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatMessageReadReceiptsCollection from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatMessageReadReceiptsCollection 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 ChatMessageReadReceiptsCollection. + */ + public static ChatMessageReadReceiptsCollection fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ChatMessageReadReceiptsCollection deserializedChatMessageReadReceiptsCollection + = new ChatMessageReadReceiptsCollection(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("value".equals(fieldName)) { + List value + = reader.readArray(reader1 -> ChatMessageReadReceipt.fromJson(reader1)); + deserializedChatMessageReadReceiptsCollection.value = value; + } else if ("nextLink".equals(fieldName)) { + deserializedChatMessageReadReceiptsCollection.nextLink = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedChatMessageReadReceiptsCollection; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessagesCollection.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessagesCollection.java index b5457ea8f662..638c90d943c4 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessagesCollection.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessagesCollection.java @@ -5,24 +5,26 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +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; /** * Collection of chat messages for a particular chat thread. */ @Fluent -public final class ChatMessagesCollection { +public final class ChatMessagesCollection implements JsonSerializable { /* * Collection of chat messages. */ - @JsonProperty(value = "value", required = true) private List value; /* * If there are more chat messages that can be retrieved, the next link will be populated. */ - @JsonProperty(value = "nextLink", access = JsonProperty.Access.WRITE_ONLY) private String nextLink; /** @@ -60,4 +62,44 @@ public ChatMessagesCollection setValue(List value) { public String getNextLink() { return this.nextLink; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeArrayField("value", this.value, (writer, element) -> writer.writeJson(element)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatMessagesCollection from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatMessagesCollection 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 ChatMessagesCollection. + */ + public static ChatMessagesCollection fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ChatMessagesCollection deserializedChatMessagesCollection = new ChatMessagesCollection(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("value".equals(fieldName)) { + List value = reader.readArray(reader1 -> ChatMessage.fromJson(reader1)); + deserializedChatMessagesCollection.value = value; + } else if ("nextLink".equals(fieldName)) { + deserializedChatMessagesCollection.nextLink = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedChatMessagesCollection; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatParticipant.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatParticipant.java index 6e82b15fc694..4b040bfd354f 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatParticipant.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatParticipant.java @@ -5,33 +5,32 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +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.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; /** * A participant of the chat thread. */ @Fluent -public final class ChatParticipant { +public final class ChatParticipant implements JsonSerializable { /* - * Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an - * Azure communication user. This model is polymorphic: Apart from kind and rawId, at most one further property may - * be set which must match the kind enum value. + * Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from kind and rawId, at most one further property may be set which must match the kind enum value. */ - @JsonProperty(value = "communicationIdentifier", required = true) private CommunicationIdentifierModel communicationIdentifier; /* * Display name for the chat participant. */ - @JsonProperty(value = "displayName") private String displayName; /* - * Time from which the chat history is shared with the participant. The timestamp is in RFC3339 format: - * `yyyy-MM-ddTHH:mm:ssZ`. + * Time from which the chat history is shared with the participant. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "shareHistoryTime") private OffsetDateTime shareHistoryTime; /** @@ -41,9 +40,9 @@ public ChatParticipant() { } /** - * Get the communicationIdentifier property: Identifies a participant in Azure Communication services. A - * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart - * from kind and rawId, at most one further property may be set which must match the kind enum value. + * Get the communicationIdentifier property: Identifies a participant in Azure Communication services. A participant + * is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from kind and + * rawId, at most one further property may be set which must match the kind enum value. * * @return the communicationIdentifier value. */ @@ -52,9 +51,9 @@ public CommunicationIdentifierModel getCommunicationIdentifier() { } /** - * Set the communicationIdentifier property: Identifies a participant in Azure Communication services. A - * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart - * from kind and rawId, at most one further property may be set which must match the kind enum value. + * Set the communicationIdentifier property: Identifies a participant in Azure Communication services. A participant + * is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from kind and + * rawId, at most one further property may be set which must match the kind enum value. * * @param communicationIdentifier the communicationIdentifier value to set. * @return the ChatParticipant object itself. @@ -85,8 +84,8 @@ public ChatParticipant setDisplayName(String displayName) { } /** - * Get the shareHistoryTime property: Time from which the chat history is shared with the participant. The - * timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. + * Get the shareHistoryTime property: Time from which the chat history is shared with the participant. The timestamp + * is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. * * @return the shareHistoryTime value. */ @@ -95,8 +94,8 @@ public OffsetDateTime getShareHistoryTime() { } /** - * Set the shareHistoryTime property: Time from which the chat history is shared with the participant. The - * timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. + * Set the shareHistoryTime property: Time from which the chat history is shared with the participant. The timestamp + * is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. * * @param shareHistoryTime the shareHistoryTime value to set. * @return the ChatParticipant object itself. @@ -105,4 +104,51 @@ public ChatParticipant setShareHistoryTime(OffsetDateTime shareHistoryTime) { this.shareHistoryTime = shareHistoryTime; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeJsonField("communicationIdentifier", this.communicationIdentifier); + jsonWriter.writeStringField("displayName", this.displayName); + jsonWriter.writeStringField("shareHistoryTime", + this.shareHistoryTime == null + ? null + : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.shareHistoryTime)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatParticipant from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatParticipant 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 ChatParticipant. + */ + public static ChatParticipant fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ChatParticipant deserializedChatParticipant = new ChatParticipant(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("communicationIdentifier".equals(fieldName)) { + deserializedChatParticipant.communicationIdentifier = CommunicationIdentifierModel.fromJson(reader); + } else if ("displayName".equals(fieldName)) { + deserializedChatParticipant.displayName = reader.getString(); + } else if ("shareHistoryTime".equals(fieldName)) { + deserializedChatParticipant.shareHistoryTime + = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); + } else { + reader.skipChildren(); + } + } + + return deserializedChatParticipant; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatParticipantsCollection.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatParticipantsCollection.java index 8492d8955f1b..a5519d829f56 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatParticipantsCollection.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatParticipantsCollection.java @@ -5,24 +5,26 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +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; /** * Collection of participants belong to a particular thread. */ @Fluent -public final class ChatParticipantsCollection { +public final class ChatParticipantsCollection implements JsonSerializable { /* * Chat participants. */ - @JsonProperty(value = "value", required = true) private List value; /* * If there are more chat participants that can be retrieved, the next link will be populated. */ - @JsonProperty(value = "nextLink", access = JsonProperty.Access.WRITE_ONLY) private String nextLink; /** @@ -60,4 +62,44 @@ public ChatParticipantsCollection setValue(List value) { public String getNextLink() { return this.nextLink; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeArrayField("value", this.value, (writer, element) -> writer.writeJson(element)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatParticipantsCollection from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatParticipantsCollection 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 ChatParticipantsCollection. + */ + public static ChatParticipantsCollection fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ChatParticipantsCollection deserializedChatParticipantsCollection = new ChatParticipantsCollection(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("value".equals(fieldName)) { + List value = reader.readArray(reader1 -> ChatParticipant.fromJson(reader1)); + deserializedChatParticipantsCollection.value = value; + } else if ("nextLink".equals(fieldName)) { + deserializedChatParticipantsCollection.nextLink = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedChatParticipantsCollection; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadItem.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadItem.java index 65a1ab061d08..f8296684489f 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadItem.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadItem.java @@ -5,38 +5,45 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +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.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; -/** Summary information of a chat thread. */ +/** + * Summary information of a chat thread. + */ @Fluent -public final class ChatThreadItem { +public final class ChatThreadItem implements JsonSerializable { /* * Chat thread id. */ - @JsonProperty(value = "id", required = true) private String id; /* * Chat thread topic. */ - @JsonProperty(value = "topic", required = true) private String topic; /* - * The timestamp when the chat thread was deleted. The timestamp is in - * RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. + * The timestamp when the chat thread was deleted. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "deletedOn") private OffsetDateTime deletedOn; /* - * The timestamp when the last message arrived at the server. The timestamp - * is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. + * The timestamp when the last message arrived at the server. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "lastMessageReceivedOn", access = JsonProperty.Access.WRITE_ONLY) private OffsetDateTime lastMessageReceivedOn; + /** + * Creates an instance of ChatThreadItem class. + */ + public ChatThreadItem() { + } + /** * Get the id property: Chat thread id. * @@ -108,4 +115,52 @@ public ChatThreadItem setDeletedOn(OffsetDateTime deletedOn) { public OffsetDateTime getLastMessageReceivedOn() { return this.lastMessageReceivedOn; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("id", this.id); + jsonWriter.writeStringField("topic", this.topic); + jsonWriter.writeStringField("deletedOn", + this.deletedOn == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.deletedOn)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatThreadItem from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatThreadItem 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 ChatThreadItem. + */ + public static ChatThreadItem fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ChatThreadItem deserializedChatThreadItem = new ChatThreadItem(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("id".equals(fieldName)) { + deserializedChatThreadItem.id = reader.getString(); + } else if ("topic".equals(fieldName)) { + deserializedChatThreadItem.topic = reader.getString(); + } else if ("deletedOn".equals(fieldName)) { + deserializedChatThreadItem.deletedOn + = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); + } else if ("lastMessageReceivedOn".equals(fieldName)) { + deserializedChatThreadItem.lastMessageReceivedOn + = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); + } else { + reader.skipChildren(); + } + } + + return deserializedChatThreadItem; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadProperties.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadProperties.java index c0a5fb37a33e..5c7e22194354 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadProperties.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadProperties.java @@ -5,44 +5,42 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +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.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; /** * Chat thread. */ @Fluent -public final class ChatThreadProperties { +public final class ChatThreadProperties implements JsonSerializable { /* * Chat thread id. */ - @JsonProperty(value = "id", required = true) private String id; /* * Chat thread topic. */ - @JsonProperty(value = "topic", required = true) private String topic; /* * The timestamp when the chat thread was created. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "createdOn", required = true) private OffsetDateTime createdOn; /* - * Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an - * Azure communication user. This model is polymorphic: Apart from kind and rawId, at most one further property may - * be set which must match the kind enum value. + * Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from kind and rawId, at most one further property may be set which must match the kind enum value. */ - @JsonProperty(value = "createdByCommunicationIdentifier", required = true) private CommunicationIdentifierModel createdByCommunicationIdentifier; /* * The timestamp when the chat thread was deleted. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "deletedOn") private OffsetDateTime deletedOn; /** @@ -115,8 +113,8 @@ public ChatThreadProperties setCreatedOn(OffsetDateTime createdOn) { /** * Get the createdByCommunicationIdentifier property: Identifies a participant in Azure Communication services. A - * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart - * from kind and rawId, at most one further property may be set which must match the kind enum value. + * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from + * kind and rawId, at most one further property may be set which must match the kind enum value. * * @return the createdByCommunicationIdentifier value. */ @@ -126,8 +124,8 @@ public CommunicationIdentifierModel getCreatedByCommunicationIdentifier() { /** * Set the createdByCommunicationIdentifier property: Identifies a participant in Azure Communication services. A - * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart - * from kind and rawId, at most one further property may be set which must match the kind enum value. + * participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from + * kind and rawId, at most one further property may be set which must match the kind enum value. * * @param createdByCommunicationIdentifier the createdByCommunicationIdentifier value to set. * @return the ChatThreadProperties object itself. @@ -159,4 +157,58 @@ public ChatThreadProperties setDeletedOn(OffsetDateTime deletedOn) { this.deletedOn = deletedOn; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("id", this.id); + jsonWriter.writeStringField("topic", this.topic); + jsonWriter.writeStringField("createdOn", + this.createdOn == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.createdOn)); + jsonWriter.writeJsonField("createdByCommunicationIdentifier", this.createdByCommunicationIdentifier); + jsonWriter.writeStringField("deletedOn", + this.deletedOn == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.deletedOn)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatThreadProperties from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatThreadProperties 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 ChatThreadProperties. + */ + public static ChatThreadProperties fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ChatThreadProperties deserializedChatThreadProperties = new ChatThreadProperties(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("id".equals(fieldName)) { + deserializedChatThreadProperties.id = reader.getString(); + } else if ("topic".equals(fieldName)) { + deserializedChatThreadProperties.topic = reader.getString(); + } else if ("createdOn".equals(fieldName)) { + deserializedChatThreadProperties.createdOn + = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); + } else if ("createdByCommunicationIdentifier".equals(fieldName)) { + deserializedChatThreadProperties.createdByCommunicationIdentifier + = CommunicationIdentifierModel.fromJson(reader); + } else if ("deletedOn".equals(fieldName)) { + deserializedChatThreadProperties.deletedOn + = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); + } else { + reader.skipChildren(); + } + } + + return deserializedChatThreadProperties; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadsItemCollection.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadsItemCollection.java index 2653a33b7df8..6a48e2caf840 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadsItemCollection.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadsItemCollection.java @@ -6,24 +6,26 @@ import com.azure.communication.chat.models.ChatThreadItem; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +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; /** * Collection of chat threads. */ @Fluent -public final class ChatThreadsItemCollection { +public final class ChatThreadsItemCollection implements JsonSerializable { /* * Collection of chat threads. */ - @JsonProperty(value = "value", required = true) private List value; /* * If there are more chat threads that can be retrieved, the next link will be populated. */ - @JsonProperty(value = "nextLink", access = JsonProperty.Access.WRITE_ONLY) private String nextLink; /** @@ -53,12 +55,51 @@ public ChatThreadsItemCollection setValue(List value) { } /** - * Get the nextLink property: If there are more chat threads that can be retrieved, the next link will be - * populated. + * Get the nextLink property: If there are more chat threads that can be retrieved, the next link will be populated. * * @return the nextLink value. */ public String getNextLink() { return this.nextLink; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeArrayField("value", this.value, (writer, element) -> writer.writeJson(element)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ChatThreadsItemCollection from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ChatThreadsItemCollection 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 ChatThreadsItemCollection. + */ + public static ChatThreadsItemCollection fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ChatThreadsItemCollection deserializedChatThreadsItemCollection = new ChatThreadsItemCollection(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("value".equals(fieldName)) { + List value = reader.readArray(reader1 -> ChatThreadItem.fromJson(reader1)); + deserializedChatThreadsItemCollection.value = value; + } else if ("nextLink".equals(fieldName)) { + deserializedChatThreadsItemCollection.nextLink = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedChatThreadsItemCollection; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationCloudEnvironmentModel.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationCloudEnvironmentModel.java index 59c431ffc8fa..f6219281caf5 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationCloudEnvironmentModel.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationCloudEnvironmentModel.java @@ -5,7 +5,6 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.util.ExpandableStringEnum; -import com.fasterxml.jackson.annotation.JsonCreator; import java.util.Collection; /** @@ -42,7 +41,6 @@ public CommunicationCloudEnvironmentModel() { * @param name a name to look for. * @return the corresponding CommunicationCloudEnvironmentModel. */ - @JsonCreator public static CommunicationCloudEnvironmentModel fromString(String name) { return fromString(name, CommunicationCloudEnvironmentModel.class); } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationError.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationError.java index 18a515ecc36d..17b68e91796f 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationError.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationError.java @@ -5,42 +5,41 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +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; /** * The Communication Services error. */ @Fluent -public final class CommunicationError { +public final class CommunicationError implements JsonSerializable { /* * The error code. */ - @JsonProperty(value = "code", required = true) private String code; /* * The error message. */ - @JsonProperty(value = "message", required = true) private String message; /* * The error target. */ - @JsonProperty(value = "target", access = JsonProperty.Access.WRITE_ONLY) private String target; /* * Further details about specific errors that led to this error. */ - @JsonProperty(value = "details", access = JsonProperty.Access.WRITE_ONLY) private List details; /* * The inner error if any. */ - @JsonProperty(value = "innererror", access = JsonProperty.Access.WRITE_ONLY) private CommunicationError innerError; /** @@ -115,4 +114,52 @@ public List getDetails() { public CommunicationError getInnerError() { return this.innerError; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("code", this.code); + jsonWriter.writeStringField("message", this.message); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of CommunicationError from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of CommunicationError 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 CommunicationError. + */ + public static CommunicationError fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + CommunicationError deserializedCommunicationError = new CommunicationError(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("code".equals(fieldName)) { + deserializedCommunicationError.code = reader.getString(); + } else if ("message".equals(fieldName)) { + deserializedCommunicationError.message = reader.getString(); + } else if ("target".equals(fieldName)) { + deserializedCommunicationError.target = reader.getString(); + } else if ("details".equals(fieldName)) { + List details + = reader.readArray(reader1 -> CommunicationError.fromJson(reader1)); + deserializedCommunicationError.details = details; + } else if ("innererror".equals(fieldName)) { + deserializedCommunicationError.innerError = CommunicationError.fromJson(reader); + } else { + reader.skipChildren(); + } + } + + return deserializedCommunicationError; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationErrorResponse.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationErrorResponse.java index ee4f0dfab4e7..f4be067601da 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationErrorResponse.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationErrorResponse.java @@ -5,17 +5,20 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; /** * The Communication Services error. */ @Fluent -public final class CommunicationErrorResponse { +public final class CommunicationErrorResponse implements JsonSerializable { /* * The Communication Services error. */ - @JsonProperty(value = "error", required = true) private CommunicationError error; /** @@ -43,4 +46,41 @@ public CommunicationErrorResponse setError(CommunicationError error) { this.error = error; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeJsonField("error", this.error); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of CommunicationErrorResponse from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of CommunicationErrorResponse 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 CommunicationErrorResponse. + */ + public static CommunicationErrorResponse fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + CommunicationErrorResponse deserializedCommunicationErrorResponse = new CommunicationErrorResponse(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("error".equals(fieldName)) { + deserializedCommunicationErrorResponse.error = CommunicationError.fromJson(reader); + } else { + reader.skipChildren(); + } + } + + return deserializedCommunicationErrorResponse; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationIdentifierModel.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationIdentifierModel.java index 61b7b4d9ca34..3aec73a3ac4d 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationIdentifierModel.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationIdentifierModel.java @@ -5,7 +5,11 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; /** * Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an Azure @@ -13,41 +17,35 @@ * which must match the kind enum value. */ @Fluent -public final class CommunicationIdentifierModel { +public final class CommunicationIdentifierModel implements JsonSerializable { /* * The identifier kind. Only required in responses. */ - @JsonProperty(value = "kind") private CommunicationIdentifierModelKind kind; /* * Raw Id of the identifier. Optional in requests, required in responses. */ - @JsonProperty(value = "rawId") private String rawId; /* * The communication user. */ - @JsonProperty(value = "communicationUser") private CommunicationUserIdentifierModel communicationUser; /* * The phone number. */ - @JsonProperty(value = "phoneNumber") private PhoneNumberIdentifierModel phoneNumber; /* * The Microsoft Teams user. */ - @JsonProperty(value = "microsoftTeamsUser") private MicrosoftTeamsUserIdentifierModel microsoftTeamsUser; /* * The Microsoft Teams application. */ - @JsonProperty(value = "microsoftTeamsApp") private MicrosoftTeamsAppIdentifierModel microsoftTeamsApp; /** @@ -175,4 +173,59 @@ public CommunicationIdentifierModel setMicrosoftTeamsApp(MicrosoftTeamsAppIdenti this.microsoftTeamsApp = microsoftTeamsApp; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("kind", this.kind == null ? null : this.kind.toString()); + jsonWriter.writeStringField("rawId", this.rawId); + jsonWriter.writeJsonField("communicationUser", this.communicationUser); + jsonWriter.writeJsonField("phoneNumber", this.phoneNumber); + jsonWriter.writeJsonField("microsoftTeamsUser", this.microsoftTeamsUser); + jsonWriter.writeJsonField("microsoftTeamsApp", this.microsoftTeamsApp); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of CommunicationIdentifierModel from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of CommunicationIdentifierModel if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the CommunicationIdentifierModel. + */ + public static CommunicationIdentifierModel fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + CommunicationIdentifierModel deserializedCommunicationIdentifierModel = new CommunicationIdentifierModel(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("kind".equals(fieldName)) { + deserializedCommunicationIdentifierModel.kind + = CommunicationIdentifierModelKind.fromString(reader.getString()); + } else if ("rawId".equals(fieldName)) { + deserializedCommunicationIdentifierModel.rawId = reader.getString(); + } else if ("communicationUser".equals(fieldName)) { + deserializedCommunicationIdentifierModel.communicationUser + = CommunicationUserIdentifierModel.fromJson(reader); + } else if ("phoneNumber".equals(fieldName)) { + deserializedCommunicationIdentifierModel.phoneNumber = PhoneNumberIdentifierModel.fromJson(reader); + } else if ("microsoftTeamsUser".equals(fieldName)) { + deserializedCommunicationIdentifierModel.microsoftTeamsUser + = MicrosoftTeamsUserIdentifierModel.fromJson(reader); + } else if ("microsoftTeamsApp".equals(fieldName)) { + deserializedCommunicationIdentifierModel.microsoftTeamsApp + = MicrosoftTeamsAppIdentifierModel.fromJson(reader); + } else { + reader.skipChildren(); + } + } + + return deserializedCommunicationIdentifierModel; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationIdentifierModelKind.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationIdentifierModelKind.java index 5ef1f17830a7..05bf437af4e0 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationIdentifierModelKind.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationIdentifierModelKind.java @@ -5,7 +5,6 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.util.ExpandableStringEnum; -import com.fasterxml.jackson.annotation.JsonCreator; import java.util.Collection; /** @@ -52,7 +51,6 @@ public CommunicationIdentifierModelKind() { * @param name a name to look for. * @return the corresponding CommunicationIdentifierModelKind. */ - @JsonCreator public static CommunicationIdentifierModelKind fromString(String name) { return fromString(name, CommunicationIdentifierModelKind.class); } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationUserIdentifierModel.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationUserIdentifierModel.java index 272519faa44a..c4b659c6510b 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationUserIdentifierModel.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CommunicationUserIdentifierModel.java @@ -5,17 +5,20 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; /** * A user that got created with an Azure Communication Services resource. */ @Fluent -public final class CommunicationUserIdentifierModel { +public final class CommunicationUserIdentifierModel implements JsonSerializable { /* * The Id of the communication user. */ - @JsonProperty(value = "id", required = true) private String id; /** @@ -43,4 +46,42 @@ public CommunicationUserIdentifierModel setId(String id) { this.id = id; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("id", this.id); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of CommunicationUserIdentifierModel from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of CommunicationUserIdentifierModel 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 CommunicationUserIdentifierModel. + */ + public static CommunicationUserIdentifierModel fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + CommunicationUserIdentifierModel deserializedCommunicationUserIdentifierModel + = new CommunicationUserIdentifierModel(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("id".equals(fieldName)) { + deserializedCommunicationUserIdentifierModel.id = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedCommunicationUserIdentifierModel; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CreateChatThreadOptions.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CreateChatThreadOptions.java index a0d57d14ecc1..6bdcf94a3bb2 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CreateChatThreadOptions.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CreateChatThreadOptions.java @@ -5,24 +5,26 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +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; /** * Request payload for creating a chat thread. */ @Fluent -public final class CreateChatThreadOptions { +public final class CreateChatThreadOptions implements JsonSerializable { /* * The chat thread topic. */ - @JsonProperty(value = "topic", required = true) private String topic; /* * Participants to be added to the chat thread. */ - @JsonProperty(value = "participants") private List participants; /** @@ -70,4 +72,45 @@ public CreateChatThreadOptions setParticipants(List participant this.participants = participants; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("topic", this.topic); + jsonWriter.writeArrayField("participants", this.participants, (writer, element) -> writer.writeJson(element)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of CreateChatThreadOptions from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of CreateChatThreadOptions 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 CreateChatThreadOptions. + */ + public static CreateChatThreadOptions fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + CreateChatThreadOptions deserializedCreateChatThreadOptions = new CreateChatThreadOptions(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("topic".equals(fieldName)) { + deserializedCreateChatThreadOptions.topic = reader.getString(); + } else if ("participants".equals(fieldName)) { + List participants = reader.readArray(reader1 -> ChatParticipant.fromJson(reader1)); + deserializedCreateChatThreadOptions.participants = participants; + } else { + reader.skipChildren(); + } + } + + return deserializedCreateChatThreadOptions; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CreateChatThreadResult.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CreateChatThreadResult.java index 0e8afb58bb96..741af7860660 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CreateChatThreadResult.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/CreateChatThreadResult.java @@ -5,24 +5,26 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +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; /** * Result of the create chat thread operation. */ @Fluent -public final class CreateChatThreadResult { +public final class CreateChatThreadResult implements JsonSerializable { /* * Chat thread. */ - @JsonProperty(value = "chatThread") private ChatThreadProperties chatThread; /* * The participants that failed to be added to the chat thread. */ - @JsonProperty(value = "invalidParticipants", access = JsonProperty.Access.WRITE_ONLY) private List invalidParticipants; /** @@ -59,4 +61,44 @@ public CreateChatThreadResult setChatThread(ChatThreadProperties chatThread) { public List getInvalidParticipants() { return this.invalidParticipants; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeJsonField("chatThread", this.chatThread); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of CreateChatThreadResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of CreateChatThreadResult if the JsonReader was pointing to an instance of it, or null if it + * was pointing to JSON null. + * @throws IOException If an error occurs while reading the CreateChatThreadResult. + */ + public static CreateChatThreadResult fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + CreateChatThreadResult deserializedCreateChatThreadResult = new CreateChatThreadResult(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("chatThread".equals(fieldName)) { + deserializedCreateChatThreadResult.chatThread = ChatThreadProperties.fromJson(reader); + } else if ("invalidParticipants".equals(fieldName)) { + List invalidParticipants + = reader.readArray(reader1 -> CommunicationError.fromJson(reader1)); + deserializedCreateChatThreadResult.invalidParticipants = invalidParticipants; + } else { + reader.skipChildren(); + } + } + + return deserializedCreateChatThreadResult; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/IndividualStatusResponse.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/IndividualStatusResponse.java index 1373c735cbba..f940fb4dcdfd 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/IndividualStatusResponse.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/IndividualStatusResponse.java @@ -5,15 +5,19 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Immutable; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; + +import java.io.IOException; /** The IndividualStatusResponse model. */ @Immutable -public final class IndividualStatusResponse { +public final class IndividualStatusResponse implements JsonSerializable { /* * Identifies the resource to which the individual status corresponds. */ - @JsonProperty(value = "id", access = JsonProperty.Access.WRITE_ONLY) private String id; /* @@ -26,21 +30,18 @@ public final class IndividualStatusResponse { * 403 for lacking permission to execute the operation, * 404 for resource not found. */ - @JsonProperty(value = "statusCode", access = JsonProperty.Access.WRITE_ONLY) private Integer statusCode; /* * The message explaining why the operation failed for the resource * identified by the key; null if the operation succeeded. */ - @JsonProperty(value = "message", access = JsonProperty.Access.WRITE_ONLY) private String message; /* * Identifies the type of the resource to which the individual status * corresponds. */ - @JsonProperty(value = "type", access = JsonProperty.Access.WRITE_ONLY) private String type; /** @@ -82,4 +83,43 @@ public String getMessage() { public String getType() { return this.type; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of SendChatMessageOptions from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of SendChatMessageOptions if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the SendChatMessageOptions. + */ + public static IndividualStatusResponse fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + final IndividualStatusResponse response = new IndividualStatusResponse(); + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("id".equals(fieldName)) { + response.id = reader.getString(); + } else if ("statusCode".equals(fieldName)) { + response.statusCode = reader.getNullable(JsonReader::getInt); + } else if ("message".equals(fieldName)) { + response.message = reader.getString(); + } else if ("type".equals(fieldName)) { + response.type = reader.getString(); + } else { + reader.skipChildren(); + } + } + return response; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/MicrosoftTeamsAppIdentifierModel.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/MicrosoftTeamsAppIdentifierModel.java index 0e052e632ba6..a354791ae301 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/MicrosoftTeamsAppIdentifierModel.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/MicrosoftTeamsAppIdentifierModel.java @@ -5,23 +5,25 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; /** * A Microsoft Teams application. */ @Fluent -public final class MicrosoftTeamsAppIdentifierModel { +public final class MicrosoftTeamsAppIdentifierModel implements JsonSerializable { /* * The Id of the Microsoft Teams application. */ - @JsonProperty(value = "appId", required = true) private String appId; /* * The cloud that the Microsoft Teams application belongs to. By default 'public' if missing. */ - @JsonProperty(value = "cloud") private CommunicationCloudEnvironmentModel cloud; /** @@ -71,4 +73,46 @@ public MicrosoftTeamsAppIdentifierModel setCloud(CommunicationCloudEnvironmentMo this.cloud = cloud; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("appId", this.appId); + jsonWriter.writeStringField("cloud", this.cloud == null ? null : this.cloud.toString()); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of MicrosoftTeamsAppIdentifierModel from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of MicrosoftTeamsAppIdentifierModel 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 MicrosoftTeamsAppIdentifierModel. + */ + public static MicrosoftTeamsAppIdentifierModel fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + MicrosoftTeamsAppIdentifierModel deserializedMicrosoftTeamsAppIdentifierModel + = new MicrosoftTeamsAppIdentifierModel(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("appId".equals(fieldName)) { + deserializedMicrosoftTeamsAppIdentifierModel.appId = reader.getString(); + } else if ("cloud".equals(fieldName)) { + deserializedMicrosoftTeamsAppIdentifierModel.cloud + = CommunicationCloudEnvironmentModel.fromString(reader.getString()); + } else { + reader.skipChildren(); + } + } + + return deserializedMicrosoftTeamsAppIdentifierModel; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/MicrosoftTeamsUserIdentifierModel.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/MicrosoftTeamsUserIdentifierModel.java index b222fbd5ca03..56b631614cb0 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/MicrosoftTeamsUserIdentifierModel.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/MicrosoftTeamsUserIdentifierModel.java @@ -5,29 +5,30 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; /** * A Microsoft Teams user. */ @Fluent -public final class MicrosoftTeamsUserIdentifierModel { +public final class MicrosoftTeamsUserIdentifierModel implements JsonSerializable { /* * The Id of the Microsoft Teams user. If not anonymous, this is the AAD object Id of the user. */ - @JsonProperty(value = "userId", required = true) private String userId; /* * True if the Microsoft Teams user is anonymous. By default false if missing. */ - @JsonProperty(value = "isAnonymous") private Boolean isAnonymous; /* * The cloud that the Microsoft Teams user belongs to. By default 'public' if missing. */ - @JsonProperty(value = "cloud") private CommunicationCloudEnvironmentModel cloud; /** @@ -97,4 +98,50 @@ public MicrosoftTeamsUserIdentifierModel setCloud(CommunicationCloudEnvironmentM this.cloud = cloud; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("userId", this.userId); + jsonWriter.writeBooleanField("isAnonymous", this.isAnonymous); + jsonWriter.writeStringField("cloud", this.cloud == null ? null : this.cloud.toString()); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of MicrosoftTeamsUserIdentifierModel from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of MicrosoftTeamsUserIdentifierModel 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 MicrosoftTeamsUserIdentifierModel. + */ + public static MicrosoftTeamsUserIdentifierModel fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + MicrosoftTeamsUserIdentifierModel deserializedMicrosoftTeamsUserIdentifierModel + = new MicrosoftTeamsUserIdentifierModel(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("userId".equals(fieldName)) { + deserializedMicrosoftTeamsUserIdentifierModel.userId = reader.getString(); + } else if ("isAnonymous".equals(fieldName)) { + deserializedMicrosoftTeamsUserIdentifierModel.isAnonymous + = reader.getNullable(JsonReader::getBoolean); + } else if ("cloud".equals(fieldName)) { + deserializedMicrosoftTeamsUserIdentifierModel.cloud + = CommunicationCloudEnvironmentModel.fromString(reader.getString()); + } else { + reader.skipChildren(); + } + } + + return deserializedMicrosoftTeamsUserIdentifierModel; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/MultiStatusResponse.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/MultiStatusResponse.java index 7c72b14b40dd..dac08107f476 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/MultiStatusResponse.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/MultiStatusResponse.java @@ -5,16 +5,20 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Immutable; -import com.fasterxml.jackson.annotation.JsonProperty; +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; /** The MultiStatusResponse model. */ @Immutable -public final class MultiStatusResponse { +public final class MultiStatusResponse implements JsonSerializable { /* * The list of status information for each resource in the request. */ - @JsonProperty(value = "multipleStatus", access = JsonProperty.Access.WRITE_ONLY) private List multipleStatus; /** @@ -25,4 +29,37 @@ public final class MultiStatusResponse { public List getMultipleStatus() { return this.multipleStatus; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of SendChatMessageOptions from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of SendChatMessageOptions if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the SendChatMessageOptions. + */ + public static MultiStatusResponse fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + final MultiStatusResponse response = new MultiStatusResponse(); + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("multipleStatus".equals(fieldName)) { + response.multipleStatus = reader.readArray(IndividualStatusResponse::fromJson); + } else { + reader.skipChildren(); + } + } + return response; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/PhoneNumberIdentifierModel.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/PhoneNumberIdentifierModel.java index 9d54537d32a2..4a0cdd678a46 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/PhoneNumberIdentifierModel.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/PhoneNumberIdentifierModel.java @@ -5,17 +5,20 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; /** * A phone number. */ @Fluent -public final class PhoneNumberIdentifierModel { +public final class PhoneNumberIdentifierModel implements JsonSerializable { /* * The phone number in E.164 format. */ - @JsonProperty(value = "value", required = true) private String value; /** @@ -43,4 +46,41 @@ public PhoneNumberIdentifierModel setValue(String value) { this.value = value; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("value", this.value); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of PhoneNumberIdentifierModel from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of PhoneNumberIdentifierModel 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 PhoneNumberIdentifierModel. + */ + public static PhoneNumberIdentifierModel fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + PhoneNumberIdentifierModel deserializedPhoneNumberIdentifierModel = new PhoneNumberIdentifierModel(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("value".equals(fieldName)) { + deserializedPhoneNumberIdentifierModel.value = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedPhoneNumberIdentifierModel; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/SendReadReceiptRequest.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/SendReadReceiptRequest.java index e56d652fc422..f79599c2bc0a 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/SendReadReceiptRequest.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/SendReadReceiptRequest.java @@ -5,17 +5,20 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; /** * Request payload for sending a read receipt. */ @Fluent -public final class SendReadReceiptRequest { +public final class SendReadReceiptRequest implements JsonSerializable { /* * Id of the latest chat message read by the user. */ - @JsonProperty(value = "chatMessageId", required = true) private String chatMessageId; /** @@ -43,4 +46,41 @@ public SendReadReceiptRequest setChatMessageId(String chatMessageId) { this.chatMessageId = chatMessageId; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("chatMessageId", this.chatMessageId); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of SendReadReceiptRequest from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of SendReadReceiptRequest 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 SendReadReceiptRequest. + */ + public static SendReadReceiptRequest fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + SendReadReceiptRequest deserializedSendReadReceiptRequest = new SendReadReceiptRequest(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("chatMessageId".equals(fieldName)) { + deserializedSendReadReceiptRequest.chatMessageId = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedSendReadReceiptRequest; + }); + } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageType.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageType.java index 7df4a08f66f2..2f7fe9f7049b 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageType.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageType.java @@ -5,7 +5,6 @@ package com.azure.communication.chat.models; import com.azure.core.util.ExpandableStringEnum; -import com.fasterxml.jackson.annotation.JsonCreator; import java.util.Collection; /** @@ -52,7 +51,6 @@ public ChatMessageType() { * @param name a name to look for. * @return the corresponding ChatMessageType. */ - @JsonCreator public static ChatMessageType fromString(String name) { return fromString(name, ChatMessageType.class); } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadItem.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadItem.java index be1c40026645..20b851de8d15 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadItem.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadItem.java @@ -5,15 +5,13 @@ package com.azure.communication.chat.models; import com.azure.core.annotation.Fluent; -import com.azure.core.util.CoreUtils; import com.azure.json.JsonReader; import com.azure.json.JsonSerializable; import com.azure.json.JsonToken; import com.azure.json.JsonWriter; -import com.fasterxml.jackson.annotation.JsonProperty; - import java.io.IOException; import java.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; /** * Summary information of a chat thread. @@ -23,26 +21,21 @@ public final class ChatThreadItem implements JsonSerializable { /* * Chat thread id. */ - @JsonProperty(value = "id", required = true) private String id; /* * Chat thread topic. */ - @JsonProperty(value = "topic", required = true) private String topic; /* * The timestamp when the chat thread was deleted. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "deletedOn") private OffsetDateTime deletedOn; /* - * The timestamp when the last message arrived at the server. The timestamp is in RFC3339 format: - * `yyyy-MM-ddTHH:mm:ssZ`. + * The timestamp when the last message arrived at the server. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "lastMessageReceivedOn", access = JsonProperty.Access.WRITE_ONLY) private OffsetDateTime lastMessageReceivedOn; /** @@ -53,7 +46,7 @@ public ChatThreadItem() { /** * Get the id property: Chat thread id. - * + * * @return the id value. */ public String getId() { @@ -62,7 +55,7 @@ public String getId() { /** * Set the id property: Chat thread id. - * + * * @param id the id value to set. * @return the ChatThreadItem object itself. */ @@ -73,7 +66,7 @@ public ChatThreadItem setId(String id) { /** * Get the topic property: Chat thread topic. - * + * * @return the topic value. */ public String getTopic() { @@ -82,7 +75,7 @@ public String getTopic() { /** * Set the topic property: Chat thread topic. - * + * * @param topic the topic value to set. * @return the ChatThreadItem object itself. */ @@ -94,7 +87,7 @@ public ChatThreadItem setTopic(String topic) { /** * Get the deletedOn property: The timestamp when the chat thread was deleted. The timestamp is in RFC3339 format: * `yyyy-MM-ddTHH:mm:ssZ`. - * + * * @return the deletedOn value. */ public OffsetDateTime getDeletedOn() { @@ -104,7 +97,7 @@ public OffsetDateTime getDeletedOn() { /** * Set the deletedOn property: The timestamp when the chat thread was deleted. The timestamp is in RFC3339 format: * `yyyy-MM-ddTHH:mm:ssZ`. - * + * * @param deletedOn the deletedOn value to set. * @return the ChatThreadItem object itself. */ @@ -116,7 +109,7 @@ public ChatThreadItem setDeletedOn(OffsetDateTime deletedOn) { /** * Get the lastMessageReceivedOn property: The timestamp when the last message arrived at the server. The timestamp * is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. - * + * * @return the lastMessageReceivedOn value. */ public OffsetDateTime getLastMessageReceivedOn() { @@ -129,51 +122,45 @@ public OffsetDateTime getLastMessageReceivedOn() { @Override public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); - jsonWriter.writeStringField("id", id); - jsonWriter.writeStringField("topic", topic); - jsonWriter.writeStringField("deletedOn", deletedOn != null ? deletedOn.toString() : null); - // Not writing 'lastMessageReceivedOn' property as it's json ready only. + jsonWriter.writeStringField("id", this.id); + jsonWriter.writeStringField("topic", this.topic); + jsonWriter.writeStringField("deletedOn", + this.deletedOn == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.deletedOn)); return jsonWriter.writeEndObject(); } /** * Reads an instance of ChatThreadItem from the JsonReader. - * + * * @param jsonReader The JsonReader being read. - * @return An instance of ChatThreadItem if the JsonReader was pointing to an instance of it, or null - * if it was pointing to JSON null. + * @return An instance of ChatThreadItem 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 ChatThreadItem. */ public static ChatThreadItem fromJson(JsonReader jsonReader) throws IOException { return jsonReader.readObject(reader -> { - final ChatThreadItem item = new ChatThreadItem(); - while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + ChatThreadItem deserializedChatThreadItem = new ChatThreadItem(); + while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); + if ("id".equals(fieldName)) { - item.setId(reader.getString()); + deserializedChatThreadItem.id = reader.getString(); } else if ("topic".equals(fieldName)) { - item.setTopic(reader.getString()); + deserializedChatThreadItem.topic = reader.getString(); } else if ("deletedOn".equals(fieldName)) { - final String value = reader.getString(); - if (!CoreUtils.isNullOrEmpty(value)) { - item.setDeletedOn(OffsetDateTime.parse(value)); - } + deserializedChatThreadItem.deletedOn + = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); } else if ("lastMessageReceivedOn".equals(fieldName)) { - final String value = reader.getString(); - if (!CoreUtils.isNullOrEmpty(value)) { - item.setLastMessageReceivedOn(OffsetDateTime.parse(value)); - } + deserializedChatThreadItem.lastMessageReceivedOn + = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); } else { reader.skipChildren(); } } - return item; - }); - } - private ChatThreadItem setLastMessageReceivedOn(OffsetDateTime lastMessageReceivedOn) { - this.lastMessageReceivedOn = lastMessageReceivedOn; - return this; + return deserializedChatThreadItem; + }); } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageOptions.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageOptions.java index e6d07cd78e9f..004e83ef3318 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageOptions.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageOptions.java @@ -9,8 +9,6 @@ import com.azure.json.JsonSerializable; import com.azure.json.JsonToken; import com.azure.json.JsonWriter; -import com.fasterxml.jackson.annotation.JsonProperty; - import java.io.IOException; import java.util.Map; @@ -22,26 +20,21 @@ public final class SendChatMessageOptions implements JsonSerializable metadata; /** @@ -52,7 +45,7 @@ public SendChatMessageOptions() { /** * Get the content property: Chat message content. - * + * * @return the content value. */ public String getContent() { @@ -61,7 +54,7 @@ public String getContent() { /** * Set the content property: Chat message content. - * + * * @param content the content value to set. * @return the SendChatMessageOptions object itself. */ @@ -73,7 +66,7 @@ public SendChatMessageOptions setContent(String content) { /** * Get the senderDisplayName property: The display name of the chat message sender. This property is used to * populate sender name for push notifications. - * + * * @return the senderDisplayName value. */ public String getSenderDisplayName() { @@ -83,7 +76,7 @@ public String getSenderDisplayName() { /** * Set the senderDisplayName property: The display name of the chat message sender. This property is used to * populate sender name for push notifications. - * + * * @param senderDisplayName the senderDisplayName value to set. * @return the SendChatMessageOptions object itself. */ @@ -94,7 +87,7 @@ public SendChatMessageOptions setSenderDisplayName(String senderDisplayName) { /** * Get the type property: The chat message type. - * + * * @return the type value. */ public ChatMessageType getType() { @@ -103,7 +96,7 @@ public ChatMessageType getType() { /** * Set the type property: The chat message type. - * + * * @param type the type value to set. * @return the SendChatMessageOptions object itself. */ @@ -114,7 +107,7 @@ public SendChatMessageOptions setType(ChatMessageType type) { /** * Get the metadata property: Message metadata. - * + * * @return the metadata value. */ public Map getMetadata() { @@ -123,7 +116,7 @@ public Map getMetadata() { /** * Set the metadata property: Message metadata. - * + * * @param metadata the metadata value to set. * @return the SendChatMessageOptions object itself. */ @@ -138,40 +131,44 @@ public SendChatMessageOptions setMetadata(Map metadata) { @Override public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); - jsonWriter.writeStringField("content", content); - jsonWriter.writeStringField("senderDisplayName", senderDisplayName); - jsonWriter.writeStringField("type", type != null ? type.toString() : null); - jsonWriter.writeMapField("metadata", metadata, JsonWriter::writeString); + jsonWriter.writeStringField("content", this.content); + jsonWriter.writeStringField("senderDisplayName", this.senderDisplayName); + jsonWriter.writeStringField("type", this.type == null ? null : this.type.toString()); + jsonWriter.writeMapField("metadata", this.metadata, (writer, element) -> writer.writeString(element)); return jsonWriter.writeEndObject(); } /** * Reads an instance of SendChatMessageOptions from the JsonReader. - * + * * @param jsonReader The JsonReader being read. - * @return An instance of SendChatMessageOptions if the JsonReader was pointing to an instance of it, or null - * if it was pointing to JSON null. + * @return An instance of SendChatMessageOptions 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 SendChatMessageOptions. */ public static SendChatMessageOptions fromJson(JsonReader jsonReader) throws IOException { return jsonReader.readObject(reader -> { - final SendChatMessageOptions options = new SendChatMessageOptions(); - while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + SendChatMessageOptions deserializedSendChatMessageOptions = new SendChatMessageOptions(); + while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); + if ("content".equals(fieldName)) { - options.setContent(reader.getString()); + deserializedSendChatMessageOptions.content = reader.getString(); } else if ("senderDisplayName".equals(fieldName)) { - options.setSenderDisplayName(reader.getString()); + deserializedSendChatMessageOptions.senderDisplayName = reader.getString(); } else if ("type".equals(fieldName)) { - options.setType(ChatMessageType.fromString(reader.getString())); + deserializedSendChatMessageOptions.type = ChatMessageType.fromString(reader.getString()); } else if ("metadata".equals(fieldName)) { - options.setMetadata(reader.readMap(JsonReader::getString)); + Map metadata = reader.readMap(reader1 -> reader1.getString()); + deserializedSendChatMessageOptions.metadata = metadata; } else { reader.skipChildren(); } } - return options; + + return deserializedSendChatMessageOptions; }); } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageResult.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageResult.java index e3d7375bbb10..5948cfda650b 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageResult.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageResult.java @@ -9,8 +9,6 @@ import com.azure.json.JsonSerializable; import com.azure.json.JsonToken; import com.azure.json.JsonWriter; -import com.fasterxml.jackson.annotation.JsonProperty; - import java.io.IOException; /** @@ -21,7 +19,6 @@ public final class SendChatMessageResult implements JsonSerializable { - SendChatMessageResult result = new SendChatMessageResult(); - while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + SendChatMessageResult deserializedSendChatMessageResult = new SendChatMessageResult(); + while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); + if ("id".equals(fieldName)) { - result.setId(reader.getString()); + deserializedSendChatMessageResult.id = reader.getString(); } else { reader.skipChildren(); } } - return result; + + return deserializedSendChatMessageResult; }); } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/TypingNotificationOptions.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/TypingNotificationOptions.java index 4193b0aa6694..caf4b03bac47 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/TypingNotificationOptions.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/TypingNotificationOptions.java @@ -9,8 +9,6 @@ import com.azure.json.JsonSerializable; import com.azure.json.JsonToken; import com.azure.json.JsonWriter; -import com.fasterxml.jackson.annotation.JsonProperty; - import java.io.IOException; /** @@ -19,10 +17,8 @@ @Fluent public final class TypingNotificationOptions implements JsonSerializable { /* - * The display name of the typing notification sender. This property is used to populate sender name for push - * notifications. + * The display name of the typing notification sender. This property is used to populate sender name for push notifications. */ - @JsonProperty(value = "senderDisplayName") private String senderDisplayName; /** @@ -34,7 +30,7 @@ public TypingNotificationOptions() { /** * Get the senderDisplayName property: The display name of the typing notification sender. This property is used to * populate sender name for push notifications. - * + * * @return the senderDisplayName value. */ public String getSenderDisplayName() { @@ -44,7 +40,7 @@ public String getSenderDisplayName() { /** * Set the senderDisplayName property: The display name of the typing notification sender. This property is used to * populate sender name for push notifications. - * + * * @param senderDisplayName the senderDisplayName value to set. * @return the TypingNotificationOptions object itself. */ @@ -59,31 +55,33 @@ public TypingNotificationOptions setSenderDisplayName(String senderDisplayName) @Override public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); - jsonWriter.writeStringField("senderDisplayName", senderDisplayName); + jsonWriter.writeStringField("senderDisplayName", this.senderDisplayName); return jsonWriter.writeEndObject(); } /** * Reads an instance of TypingNotificationOptions from the JsonReader. - * + * * @param jsonReader The JsonReader being read. - * @return An instance of TypingNotificationOptions if the JsonReader was pointing to an instance of it, or null - * if it was pointing to JSON null. + * @return An instance of TypingNotificationOptions if the JsonReader was pointing to an instance of it, or null if + * it was pointing to JSON null. * @throws IOException If an error occurs while reading the TypingNotificationOptions. */ public static TypingNotificationOptions fromJson(JsonReader jsonReader) throws IOException { return jsonReader.readObject(reader -> { - TypingNotificationOptions options = new TypingNotificationOptions(); - while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + TypingNotificationOptions deserializedTypingNotificationOptions = new TypingNotificationOptions(); + while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); + if ("senderDisplayName".equals(fieldName)) { - options.setSenderDisplayName(reader.getString()); + deserializedTypingNotificationOptions.senderDisplayName = reader.getString(); } else { reader.skipChildren(); } } - return options; + + return deserializedTypingNotificationOptions; }); } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/UpdateChatMessageOptions.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/UpdateChatMessageOptions.java index 3371981fcdf7..58679fb47a00 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/UpdateChatMessageOptions.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/UpdateChatMessageOptions.java @@ -9,8 +9,6 @@ import com.azure.json.JsonSerializable; import com.azure.json.JsonToken; import com.azure.json.JsonWriter; -import com.fasterxml.jackson.annotation.JsonProperty; - import java.io.IOException; import java.util.Map; @@ -22,13 +20,11 @@ public final class UpdateChatMessageOptions implements JsonSerializable metadata; /** @@ -39,7 +35,7 @@ public UpdateChatMessageOptions() { /** * Get the content property: Chat message content. - * + * * @return the content value. */ public String getContent() { @@ -48,7 +44,7 @@ public String getContent() { /** * Set the content property: Chat message content. - * + * * @param content the content value to set. * @return the UpdateChatMessageOptions object itself. */ @@ -59,7 +55,7 @@ public UpdateChatMessageOptions setContent(String content) { /** * Get the metadata property: Message metadata. - * + * * @return the metadata value. */ public Map getMetadata() { @@ -68,7 +64,7 @@ public Map getMetadata() { /** * Set the metadata property: Message metadata. - * + * * @param metadata the metadata value to set. * @return the UpdateChatMessageOptions object itself. */ @@ -83,34 +79,37 @@ public UpdateChatMessageOptions setMetadata(Map metadata) { @Override public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); - jsonWriter.writeStringField("content", content); - jsonWriter.writeMapField("metadata", metadata, JsonWriter::writeString); + jsonWriter.writeStringField("content", this.content); + jsonWriter.writeMapField("metadata", this.metadata, (writer, element) -> writer.writeString(element)); return jsonWriter.writeEndObject(); } /** - * Reads an instance of SendChatMessageOptions from the JsonReader. - * + * Reads an instance of UpdateChatMessageOptions from the JsonReader. + * * @param jsonReader The JsonReader being read. - * @return An instance of SendChatMessageOptions if the JsonReader was pointing to an instance of it, or null - * if it was pointing to JSON null. - * @throws IOException If an error occurs while reading the SendChatMessageOptions. + * @return An instance of UpdateChatMessageOptions if the JsonReader was pointing to an instance of it, or null if + * it was pointing to JSON null. + * @throws IOException If an error occurs while reading the UpdateChatMessageOptions. */ - public static SendChatMessageOptions fromJson(JsonReader jsonReader) throws IOException { + public static UpdateChatMessageOptions fromJson(JsonReader jsonReader) throws IOException { return jsonReader.readObject(reader -> { - final SendChatMessageOptions options = new SendChatMessageOptions(); - while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + UpdateChatMessageOptions deserializedUpdateChatMessageOptions = new UpdateChatMessageOptions(); + while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); + if ("content".equals(fieldName)) { - options.setContent(reader.getString()); + deserializedUpdateChatMessageOptions.content = reader.getString(); } else if ("metadata".equals(fieldName)) { - options.setMetadata(reader.readMap(JsonReader::getString)); + Map metadata = reader.readMap(reader1 -> reader1.getString()); + deserializedUpdateChatMessageOptions.metadata = metadata; } else { reader.skipChildren(); } } - return options; + + return deserializedUpdateChatMessageOptions; }); } } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/UpdateChatThreadOptions.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/UpdateChatThreadOptions.java index 9b40c8375f11..fa8cf0ec59c4 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/UpdateChatThreadOptions.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/UpdateChatThreadOptions.java @@ -9,8 +9,6 @@ import com.azure.json.JsonSerializable; import com.azure.json.JsonToken; import com.azure.json.JsonWriter; -import com.fasterxml.jackson.annotation.JsonProperty; - import java.io.IOException; /** @@ -21,7 +19,6 @@ public final class UpdateChatThreadOptions implements JsonSerializable { - UpdateChatThreadOptions options = new UpdateChatThreadOptions(); - while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + UpdateChatThreadOptions deserializedUpdateChatThreadOptions = new UpdateChatThreadOptions(); + while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); + if ("topic".equals(fieldName)) { - options.setTopic(reader.getString()); + deserializedUpdateChatThreadOptions.topic = reader.getString(); } else { reader.skipChildren(); } } - return options; + + return deserializedUpdateChatThreadOptions; }); } } diff --git a/sdk/communication/azure-communication-chat/swagger/README.md b/sdk/communication/azure-communication-chat/swagger/README.md index 3e20d078f140..512409d70cb0 100644 --- a/sdk/communication/azure-communication-chat/swagger/README.md +++ b/sdk/communication/azure-communication-chat/swagger/README.md @@ -36,7 +36,7 @@ To update generated files for chat service, run the following command ```yaml tag: package-chat-2024-03-07 -use: '@autorest/java@4.1.25' +use: '@autorest/java@4.1.29' require: - https://raw.githubusercontent.com/Azure/azure-rest-api-specs/72d4c8cae964a12dc27ad4684b0bddf493225338/specification/communication/data-plane/Chat/readme.md java: true From 303c3d0e17732479ce112636b82d4b0e4d5b434b Mon Sep 17 00:00:00 2001 From: anuchandy Date: Fri, 28 Jun 2024 14:58:55 -0700 Subject: [PATCH 3/7] Adjust ChatAsyncClient to use newly generated service client --- .../main/java/com/azure/communication/chat/ChatAsyncClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/ChatAsyncClient.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/ChatAsyncClient.java index e3866bd5b11b..e2b3f213a48e 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/ChatAsyncClient.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/ChatAsyncClient.java @@ -167,7 +167,7 @@ Mono> createChatThread(CreateChatThreadOptions context = context == null ? Context.NONE : context; try { return this.chatClient.createChatThreadWithResponseAsync( - CreateChatThreadOptionsConverter.convert(options), options.getIdempotencyToken(), context) + CreateChatThreadOptionsConverter.convert(options), context) .onErrorMap(CommunicationErrorResponseException.class, e -> translateException(e)) .map(result -> new SimpleResponse( result, CreateChatThreadResultConverter.convert(result.getValue()))); From 49652038fedadb1946000044ebc041cc737e9ef2 Mon Sep 17 00:00:00 2001 From: anuchandy Date: Fri, 28 Jun 2024 15:10:42 -0700 Subject: [PATCH 4/7] remove jackson annotations from the hand written models --- .../models/AddChatParticipantsResult.java | 2 -- .../chat/models/ChatAttachmentType.java | 2 -- .../chat/models/ChatMessage.java | 20 ++++----------- .../chat/models/ChatMessageContent.java | 23 +++++++---------- .../chat/models/ChatMessageReadReceipt.java | 15 +++++------ .../chat/models/ChatParticipant.java | 25 ++++++++----------- .../chat/models/ChatThreadProperties.java | 14 +++++------ .../chat/models/CreateChatThreadResult.java | 3 --- 8 files changed, 37 insertions(+), 67 deletions(-) diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/AddChatParticipantsResult.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/AddChatParticipantsResult.java index 6855523afed4..be5010e80684 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/AddChatParticipantsResult.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/AddChatParticipantsResult.java @@ -9,7 +9,6 @@ import com.azure.json.JsonSerializable; import com.azure.json.JsonToken; import com.azure.json.JsonWriter; -import com.fasterxml.jackson.annotation.JsonProperty; import java.io.IOException; import java.util.List; @@ -22,7 +21,6 @@ public final class AddChatParticipantsResult implements JsonSerializable invalidParticipants; /** diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatAttachmentType.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatAttachmentType.java index 07bc66d49b5b..c174bd36e29f 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatAttachmentType.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatAttachmentType.java @@ -4,7 +4,6 @@ package com.azure.communication.chat.models; import com.azure.core.util.ExpandableStringEnum; -import com.fasterxml.jackson.annotation.JsonCreator; import java.util.Collection; /** @@ -23,7 +22,6 @@ public final class ChatAttachmentType extends ExpandableStringEnum { /** * The id of the chat message. */ - @JsonProperty(value = "id", required = true) private String id; /** * Type of the chat message. * */ - @JsonProperty(value = "type", required = true) private ChatMessageType type; /** * Version of the chat message. */ - @JsonProperty(value = "version", required = true) private String version; /** * Content of the chat message. */ - @JsonProperty(value = "content") private ChatMessageContent content; /** * The display name of the chat message sender. This property is used to * populate sender name for push notifications. */ - @JsonProperty(value = "senderDisplayName") private String senderDisplayName; /** * The timestamp when the chat message arrived at the server. The timestamp * is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "createdOn") private OffsetDateTime createdOn; /** @@ -66,27 +61,23 @@ public final class ChatMessage implements JsonSerializable { * model must be interpreted as a union: Apart from rawId, at most one * further property may be set. */ - @JsonProperty(value = "senderCommunicationIdentifier") private CommunicationIdentifier sender; /** * The timestamp when the chat message was deleted. The timestamp is in * RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "deletedOn") private OffsetDateTime deletedOn; /** * The timestamp when the chat message was edited. The timestamp is in * RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "editedOn") private OffsetDateTime editedOn; /** * Message metadata. */ - @JsonProperty(value = "metadata") private Map metadata; /** @@ -353,10 +344,9 @@ public static ChatMessage fromJson(JsonReader jsonReader) throws IOException { if (!CoreUtils.isNullOrEmpty(value)) { message.setCreatedOn(OffsetDateTime.parse(value)); } - // } else if ("senderCommunicationIdentifier".equals(fieldName)) { - // TODO (anu) : uncomment this after generating protocol layer - // final CommunicationIdentifierModel identifier = reader.readObject(CommunicationIdentifierModel::fromJson); - // receipt.setSender(CommunicationIdentifierConverter.convert(identifier)); + } else if ("senderCommunicationIdentifier".equals(fieldName)) { + final CommunicationIdentifierModel identifier = reader.readObject(CommunicationIdentifierModel::fromJson); + message.setSender(CommunicationIdentifierConverter.convert(identifier)); } else if ("deletedOn".equals(fieldName)) { final String value = reader.getString(); if (!CoreUtils.isNullOrEmpty(value)) { diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageContent.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageContent.java index 24aa9d27408e..a2471bd41e1a 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageContent.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageContent.java @@ -3,13 +3,14 @@ package com.azure.communication.chat.models; +import com.azure.communication.chat.implementation.converters.CommunicationIdentifierConverter; +import com.azure.communication.chat.implementation.models.CommunicationIdentifierModel; import com.azure.communication.common.CommunicationIdentifier; import com.azure.core.annotation.Fluent; import com.azure.json.JsonReader; import com.azure.json.JsonSerializable; import com.azure.json.JsonToken; import com.azure.json.JsonWriter; -import com.fasterxml.jackson.annotation.JsonProperty; import java.io.IOException; import java.util.List; @@ -20,20 +21,15 @@ @Fluent public final class ChatMessageContent implements JsonSerializable { - @JsonProperty(value = "message") - private String message; + private final String message; - @JsonProperty(value = "topic") - private String topic; + private final String topic; - @JsonProperty(value = "participants") - private Iterable participants; + private final Iterable participants; - @JsonProperty(value = "attachments") private Iterable attachments; - @JsonProperty(value = "initiatorCommunicationIdentifier") - private CommunicationIdentifier initiator; + private final CommunicationIdentifier initiator; /** * Constructs a new ChatMessageContent @@ -154,10 +150,9 @@ public static ChatMessageContent fromJson(JsonReader jsonReader) throws IOExcept participants = reader.readArray(ChatParticipant::fromJson); } else if ("attachments".equals(fieldName)) { attachments = reader.readArray(ChatAttachment::fromJson); - // } else if ("initiatorCommunicationIdentifier".equals(fieldName)) { - // TODO (anu) : uncomment this after generating protocol layer - // final CommunicationIdentifierModel identifier = reader.readObject(CommunicationIdentifierModel::fromJson); - // initiator = CommunicationIdentifierConverter.convert(identifier); + } else if ("initiatorCommunicationIdentifier".equals(fieldName)) { + final CommunicationIdentifierModel identifier = reader.readObject(CommunicationIdentifierModel::fromJson); + initiator = CommunicationIdentifierConverter.convert(identifier); } else { reader.skipChildren(); } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageReadReceipt.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageReadReceipt.java index c341496281d5..2e379e0d1dc3 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageReadReceipt.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatMessageReadReceipt.java @@ -3,6 +3,8 @@ package com.azure.communication.chat.models; +import com.azure.communication.chat.implementation.converters.CommunicationIdentifierConverter; +import com.azure.communication.chat.implementation.models.CommunicationIdentifierModel; import com.azure.communication.common.CommunicationIdentifier; import com.azure.core.annotation.Fluent; import com.azure.core.util.CoreUtils; @@ -10,7 +12,6 @@ import com.azure.json.JsonSerializable; import com.azure.json.JsonToken; import com.azure.json.JsonWriter; -import com.fasterxml.jackson.annotation.JsonProperty; import java.io.IOException; import java.time.OffsetDateTime; @@ -26,21 +27,18 @@ public final class ChatMessageReadReceipt implements JsonSerializable * model must be interpreted as a union: Apart from rawId, at most one * further property may be set. */ - @JsonProperty(value = "communicationIdentifier", required = true) private CommunicationIdentifier communicationIdentifier; /** * Display name for the chat participant. */ - @JsonProperty(value = "displayName") private String displayName; /** * Time from which the chat history is shared with the member. The * timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. */ - @JsonProperty(value = "shareHistoryTime") private OffsetDateTime shareHistoryTime; /** @@ -114,11 +111,10 @@ public ChatParticipant setShareHistoryTime(OffsetDateTime shareHistoryTime) { @Override public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); - // TODO (anu) : uncomment this after generating protocol layer - // final CommunicationIdentifierModel identifier = CommunicationIdentifierConverter.convert(communicationIdentifier); - // jsonWriter.writeJsonField("communicationIdentifier", identifier); + final CommunicationIdentifierModel identifier = CommunicationIdentifierConverter.convert(communicationIdentifier); + jsonWriter.writeJsonField("communicationIdentifier", identifier); jsonWriter.writeStringField("displayName", displayName); - jsonWriter.writeStringField("startDateTime", shareHistoryTime.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)); + jsonWriter.writeStringField("startDateTime", shareHistoryTime.toString()); return jsonWriter.writeEndObject(); } @@ -136,14 +132,13 @@ public static ChatParticipant fromJson(JsonReader jsonReader) throws IOException while (jsonReader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); - // if ("communicationIdentifier".equals(fieldName)) { - // TODO (anu) : uncomment this after generating protocol layer - // final CommunicationIdentifierModel identifier = reader.readObject(CommunicationIdentifierModel::fromJson); - // participant.communicationIdentifier = CommunicationIdentifierConverter.convert(identifier); - if ("displayName".equals(fieldName)) { + if ("communicationIdentifier".equals(fieldName)) { + final CommunicationIdentifierModel identifier = reader.readObject(CommunicationIdentifierModel::fromJson); + participant.communicationIdentifier = CommunicationIdentifierConverter.convert(identifier); + } else if ("displayName".equals(fieldName)) { participant.displayName = reader.getString(); } else if ("startDateTime".equals(fieldName)) { - participant.shareHistoryTime = OffsetDateTime.parse(reader.getString(), DateTimeFormatter.ISO_OFFSET_DATE_TIME); + participant.shareHistoryTime = OffsetDateTime.parse(reader.getString()); } else { reader.skipChildren(); } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadProperties.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadProperties.java index 8f24aeaa0f65..5e89ff2f1178 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadProperties.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadProperties.java @@ -3,6 +3,8 @@ package com.azure.communication.chat.models; +import com.azure.communication.chat.implementation.converters.CommunicationIdentifierConverter; +import com.azure.communication.chat.implementation.models.CommunicationIdentifierModel; import com.azure.communication.common.CommunicationIdentifier; import com.azure.core.annotation.Fluent; import com.azure.core.util.CoreUtils; @@ -123,9 +125,8 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStringField("id", id); jsonWriter.writeStringField("topic", topic); jsonWriter.writeStringField("createdOn", createdOn != null ? createdOn.toString() : null); - // TODO (anu) : uncomment this after generating protocol layer - // final CommunicationIdentifierModel identifier = CommunicationIdentifierConverter.convert(createdBy); - // jsonWriter.writeJsonField("createdBy", identifier); + final CommunicationIdentifierModel identifier = CommunicationIdentifierConverter.convert(createdBy); + jsonWriter.writeJsonField("createdBy", identifier); return jsonWriter.writeEndObject(); } @@ -152,10 +153,9 @@ public static ChatThreadProperties fromJson(JsonReader jsonReader) throws IOExce if (!CoreUtils.isNullOrEmpty(value)) { properties.setCreatedOn(OffsetDateTime.parse(value)); } - // } else if ("createdBy".equals(fieldName)) { - // TODO (anu) : uncomment this after generating protocol layer - // final CommunicationIdentifierModel identifier = reader.readObject(CommunicationIdentifierModel::fromJson); - // properties.setCreatedBy(CommunicationIdentifierConverter.convert(identifier)); + } else if ("createdBy".equals(fieldName)) { + final CommunicationIdentifierModel identifier = reader.readObject(CommunicationIdentifierModel::fromJson); + properties.setCreatedBy(CommunicationIdentifierConverter.convert(identifier)); } else { reader.skipChildren(); } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/CreateChatThreadResult.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/CreateChatThreadResult.java index 05bf2d1fe6eb..8f1c0dcb089c 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/CreateChatThreadResult.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/CreateChatThreadResult.java @@ -8,7 +8,6 @@ import com.azure.json.JsonSerializable; import com.azure.json.JsonToken; import com.azure.json.JsonWriter; -import com.fasterxml.jackson.annotation.JsonProperty; import java.io.IOException; import java.util.List; @@ -21,13 +20,11 @@ public final class CreateChatThreadResult implements JsonSerializable invalidParticipants; /** From b8755faae26138a930c02aad6244089cc94e0b05 Mon Sep 17 00:00:00 2001 From: anuchandy Date: Fri, 28 Jun 2024 15:50:02 -0700 Subject: [PATCH 5/7] migrate chat tests to use azure-json --- .../chat/ChatResponseMocker.java | 153 ++++++++++++++---- 1 file changed, 125 insertions(+), 28 deletions(-) diff --git a/sdk/communication/azure-communication-chat/src/test/java/com/azure/communication/chat/ChatResponseMocker.java b/sdk/communication/azure-communication-chat/src/test/java/com/azure/communication/chat/ChatResponseMocker.java index 9650d106d835..b4ac8c4c024f 100644 --- a/sdk/communication/azure-communication-chat/src/test/java/com/azure/communication/chat/ChatResponseMocker.java +++ b/sdk/communication/azure-communication-chat/src/test/java/com/azure/communication/chat/ChatResponseMocker.java @@ -3,6 +3,8 @@ package com.azure.communication.chat; +import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; @@ -18,9 +20,11 @@ import com.azure.core.http.HttpRequest; import com.azure.core.http.HttpResponse; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; +import com.azure.json.JsonProviders; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -48,14 +52,7 @@ public static HttpResponse createChatThreadInvalidParticipantResponse(HttpReques .setId("000")) .setInvalidParticipants(invalidParticipants); - ObjectMapper mapper = new ObjectMapper(); - String body = null; - try { - body = mapper.writeValueAsString(result); - } catch (JsonProcessingException e) { - e.printStackTrace(); - } - + final String body = serializeObject(result); return generateMockResponse(body, request, 201); } @@ -67,14 +64,7 @@ public static HttpResponse addParticipantsInvalidParticipantResponse(HttpRequest MockAddChatParticipantsResult result = new MockAddChatParticipantsResult() .setInvalidParticipants(invalidParticipants); - ObjectMapper mapper = new ObjectMapper(); - String body = null; - try { - body = mapper.writeValueAsString(result); - } catch (JsonProcessingException e) { - e.printStackTrace(); - } - + final String body = serializeObject(result); return generateMockResponse(body, request, 201); } @@ -125,12 +115,10 @@ public Mono getBodyAsString(Charset charset) { }; } - static class MockCreateChatThreadResult { + static class MockCreateChatThreadResult implements JsonSerializable { - @JsonProperty(value = "chatThread") private ChatThreadProperties chatThread; - @JsonProperty(value = "invalidParticipants") private List invalidParticipants; public ChatThreadProperties getChatThread() { @@ -150,11 +138,47 @@ public MockCreateChatThreadResult setInvalidParticipants(List error.toJson(writer)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of MockCreateChatThreadResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of MockCreateChatThreadResult if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the MockCreateChatThreadResult. + */ + public static MockCreateChatThreadResult fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + final MockCreateChatThreadResult result = new MockCreateChatThreadResult(); + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("chatThread".equals(fieldName)) { + result.setChatThread(ChatThreadProperties.fromJson(jsonReader)); + } else if ("invalidParticipants".equals(fieldName)) { + result.setInvalidParticipants(reader.readArray(MockCommunicationError::fromJson)); + } else { + reader.skipChildren(); + } + } + return result; + }); + } } - static class MockAddChatParticipantsResult { + static class MockAddChatParticipantsResult implements JsonSerializable { - @JsonProperty(value = "invalidParticipants") private List invalidParticipants; public List getInvalidParticipants() { @@ -165,17 +189,48 @@ public MockAddChatParticipantsResult setInvalidParticipants(List error.toJson(writer)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of MockAddChatParticipantsResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of MockAddChatParticipantsResult if the JsonReader was pointing to an instance of it, or null + * if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the MockAddChatParticipantsResult. + */ + public static MockAddChatParticipantsResult fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + final MockAddChatParticipantsResult result = new MockAddChatParticipantsResult(); + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("invalidParticipants".equals(fieldName)) { + result.setInvalidParticipants(reader.readArray(MockCommunicationError::fromJson)); + } else { + reader.skipChildren(); + } + } + return result; + }); + } } - static class MockCommunicationError { + static class MockCommunicationError implements JsonSerializable { - @JsonProperty(value = "code") private String code; - @JsonProperty(value = "message") private String message; - @JsonProperty(value = "target") private String target; public String getCode() { @@ -204,6 +259,48 @@ public MockCommunicationError setTarget(String target) { this.target = target; return this; } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("code", code); + jsonWriter.writeStringField("message", message); + jsonWriter.writeStringField("target", target); + return jsonWriter.writeEndObject(); + } + + public static MockCommunicationError fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + final MockCommunicationError error = new MockCommunicationError(); + while (jsonReader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + if ("code".equals(fieldName)) { + error.setCode(reader.getString()); + } else if ("message".equals(fieldName)) { + error.setMessage(reader.getString()); + } else if ("target".equals(fieldName)) { + error.setTarget(reader.getString()); + } else { + reader.skipChildren(); + } + } + return error; + }); + } } + private static String serializeObject(JsonSerializable o) { + try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + JsonWriter writer = JsonProviders.createWriter(outputStream)) { + o.toJson(writer); + writer.flush(); + return outputStream.toString(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } } From 0372ff9579b8ff6913e281b42db7209666a33e0c Mon Sep 17 00:00:00 2001 From: anuchandy Date: Tue, 9 Jul 2024 17:15:13 -0700 Subject: [PATCH 6/7] refresh protocol layer with autorest-4.1.33 --- ...reCommunicationChatServiceImplBuilder.java | 15 ++++-- .../chat/implementation/ChatThreadsImpl.java | 48 +++++-------------- .../chat/implementation/ChatsImpl.java | 30 ++++-------- .../implementation/models/ChatMessage.java | 29 ++++++----- .../models/ChatMessageContent.java | 4 +- .../models/ChatMessageReadReceipt.java | 9 ++-- .../models/ChatParticipant.java | 12 +++-- .../models/ChatThreadProperties.java | 13 +++-- .../chat/models/ChatThreadItem.java | 12 +++-- .../chat/models/SendChatMessageOptions.java | 3 +- .../models/TypingNotificationOptions.java | 3 +- .../swagger/README.md | 2 +- 12 files changed, 86 insertions(+), 94 deletions(-) diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/AzureCommunicationChatServiceImplBuilder.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/AzureCommunicationChatServiceImplBuilder.java index 2fa0a2c5241a..4d29bb960ea7 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/AzureCommunicationChatServiceImplBuilder.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/AzureCommunicationChatServiceImplBuilder.java @@ -12,7 +12,6 @@ import com.azure.core.client.traits.HttpTrait; import com.azure.core.credential.AzureKeyCredential; import com.azure.core.http.HttpClient; -import com.azure.core.http.HttpHeaderName; import com.azure.core.http.HttpHeaders; import com.azure.core.http.HttpPipeline; import com.azure.core.http.HttpPipelineBuilder; @@ -269,6 +268,7 @@ public AzureCommunicationChatServiceImplBuilder retryPolicy(RetryPolicy retryPol */ @Generated public AzureCommunicationChatServiceImpl buildClient() { + this.validateClient(); HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline(); String localApiVersion = (apiVersion != null) ? apiVersion : "2024-03-07"; SerializerAdapter localSerializerAdapter @@ -278,6 +278,13 @@ public AzureCommunicationChatServiceImpl buildClient() { return client; } + @Generated + private void validateClient() { + // This method is invoked from 'buildInnerClient'/'buildClient' method. + // Developer can customize this method, to validate that the necessary conditions are met for the new client. + Objects.requireNonNull(endpoint, "'endpoint' cannot be null."); + } + @Generated private HttpPipeline createHttpPipeline() { Configuration buildConfiguration @@ -291,10 +298,8 @@ private HttpPipeline createHttpPipeline() { policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion, buildConfiguration)); policies.add(new RequestIdPolicy()); policies.add(new AddHeadersFromContextPolicy()); - HttpHeaders headers = new HttpHeaders(); - localClientOptions.getHeaders() - .forEach(header -> headers.set(HttpHeaderName.fromString(header.getName()), header.getValue())); - if (headers.getSize() > 0) { + HttpHeaders headers = CoreUtils.createHttpHeadersFromClientOptions(localClientOptions); + if (headers != null) { policies.add(new AddHeadersPolicy(headers)); } this.pipelinePolicies.stream() diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/ChatThreadsImpl.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/ChatThreadsImpl.java index 46e9fbf4d5c6..30039164d9d5 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/ChatThreadsImpl.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/ChatThreadsImpl.java @@ -2063,9 +2063,7 @@ public void sendTypingNotification(String chatThreadId) { /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. * @throws CommunicationErrorResponseException thrown if the request is rejected by server on status code 401, 403, @@ -2087,9 +2085,7 @@ public Mono> listChatReadReceiptsNextSingl /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. @@ -2111,9 +2107,7 @@ public Mono> listChatReadReceiptsNextSingl /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. * @throws CommunicationErrorResponseException thrown if the request is rejected by server on status code 401, 403, @@ -2129,9 +2123,7 @@ public PagedResponse listChatReadReceiptsNextSinglePage( /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. @@ -2148,9 +2140,7 @@ public PagedResponse listChatReadReceiptsNextSinglePage( /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. * @throws CommunicationErrorResponseException thrown if the request is rejected by server on status code 401, 403, @@ -2171,9 +2161,7 @@ public Mono> listChatMessagesNextSinglePageAsync(Stri /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. @@ -2194,9 +2182,7 @@ public Mono> listChatMessagesNextSinglePageAsync(Stri /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. * @throws CommunicationErrorResponseException thrown if the request is rejected by server on status code 401, 403, @@ -2212,9 +2198,7 @@ public PagedResponse listChatMessagesNextSinglePage(String nextLink /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. @@ -2231,9 +2215,7 @@ public PagedResponse listChatMessagesNextSinglePage(String nextLink /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. * @throws CommunicationErrorResponseException thrown if the request is rejected by server on status code 401, 403, @@ -2255,9 +2237,7 @@ public Mono> listChatParticipantsNextSinglePageAs /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. @@ -2279,9 +2259,7 @@ public Mono> listChatParticipantsNextSinglePageAs /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. * @throws CommunicationErrorResponseException thrown if the request is rejected by server on status code 401, 403, @@ -2297,9 +2275,7 @@ public PagedResponse listChatParticipantsNextSinglePage(String /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/ChatsImpl.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/ChatsImpl.java index 4ed905418c24..dea89e8d8093 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/ChatsImpl.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/ChatsImpl.java @@ -30,10 +30,9 @@ import com.azure.core.http.rest.Response; import com.azure.core.http.rest.RestProxy; import com.azure.core.util.Context; -import com.azure.core.util.DateTimeRfc1123; +import com.azure.core.util.CoreUtils; import com.azure.core.util.FluxUtil; import java.time.OffsetDateTime; -import java.util.UUID; import reactor.core.publisher.Mono; /** @@ -76,7 +75,8 @@ public interface ChatsService { Mono> createChatThread(@HostParam("endpoint") String endpoint, @QueryParam("api-version") String apiVersion, @BodyParam("application/json") CreateChatThreadOptions createChatThreadRequest, - @HeaderParam("Accept") String accept, Context context); + @HeaderParam("Accept") String accept, + @HeaderParam("repeatability-request-id") String repeatabilityRequestId, Context context); @Get("/chat/threads") @ExpectedResponses({ 200 }) @@ -125,10 +125,8 @@ Mono> listChatThreadsNext( public Mono> createChatThreadWithResponseAsync(CreateChatThreadOptions createChatThreadRequest) { final String accept = "application/json"; - String repeatabilityRequestId = UUID.randomUUID().toString(); - String repeatabilityFirstSent = DateTimeRfc1123.toRfc1123String(OffsetDateTime.now()); return FluxUtil.withContext(context -> service.createChatThread(this.client.getEndpoint(), - this.client.getApiVersion(), createChatThreadRequest, accept, context)); + this.client.getApiVersion(), createChatThreadRequest, accept, CoreUtils.randomUuid().toString(), context)); } /** @@ -148,10 +146,8 @@ Mono> listChatThreadsNext( public Mono> createChatThreadWithResponseAsync(CreateChatThreadOptions createChatThreadRequest, Context context) { final String accept = "application/json"; - String repeatabilityRequestId = UUID.randomUUID().toString(); - String repeatabilityFirstSent = DateTimeRfc1123.toRfc1123String(OffsetDateTime.now()); return service.createChatThread(this.client.getEndpoint(), this.client.getApiVersion(), createChatThreadRequest, - accept, context); + accept, CoreUtils.randomUuid().toString(), context); } /** @@ -529,9 +525,7 @@ public void deleteChatThread(String chatThreadId) { /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. * @throws CommunicationErrorResponseException thrown if the request is rejected by server on status code 401, 403, @@ -551,9 +545,7 @@ public Mono> listChatThreadsNextSinglePageAsync(St /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. @@ -573,9 +565,7 @@ public Mono> listChatThreadsNextSinglePageAsync(St /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. * @throws CommunicationErrorResponseException thrown if the request is rejected by server on status code 401, 403, @@ -591,9 +581,7 @@ public PagedResponse listChatThreadsNextSinglePage(String nextLi /** * Get the next page of items. * - * @param nextLink The URL to get the next list of items - * - * The nextLink parameter. + * @param nextLink The URL to get the next list of items. * @param context The context to associate with this operation. * @throws IllegalArgumentException thrown if parameters fail the validation. * @throws CommunicationErrorResponseException thrown if the request is rejected by server. diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessage.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessage.java index 2a75b82c97f6..214fb8cc7294 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessage.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessage.java @@ -6,6 +6,7 @@ import com.azure.communication.chat.models.ChatMessageType; import com.azure.core.annotation.Fluent; +import com.azure.core.util.CoreUtils; import com.azure.json.JsonReader; import com.azure.json.JsonSerializable; import com.azure.json.JsonToken; @@ -46,27 +47,33 @@ public final class ChatMessage implements JsonSerializable { private ChatMessageContent content; /* - * The display name of the chat message sender. This property is used to populate sender name for push notifications. + * The display name of the chat message sender. This property is used to populate sender name for push + * notifications. */ private String senderDisplayName; /* - * The timestamp when the chat message arrived at the server. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. + * The timestamp when the chat message arrived at the server. The timestamp is in RFC3339 format: + * `yyyy-MM-ddTHH:mm:ssZ`. */ private OffsetDateTime createdOn; /* - * Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from kind and rawId, at most one further property may be set which must match the kind enum value. + * Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an + * Azure communication user. This model is polymorphic: Apart from kind and rawId, at most one further property may + * be set which must match the kind enum value. */ private CommunicationIdentifierModel senderCommunicationIdentifier; /* - * The timestamp (if applicable) when the message was deleted. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. + * The timestamp (if applicable) when the message was deleted. The timestamp is in RFC3339 format: + * `yyyy-MM-ddTHH:mm:ssZ`. */ private OffsetDateTime deletedOn; /* - * The last timestamp (if applicable) when the message was edited. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. + * The last timestamp (if applicable) when the message was edited. The timestamp is in RFC3339 format: + * `yyyy-MM-ddTHH:mm:ssZ`. */ private OffsetDateTime editedOn; @@ -361,8 +368,8 @@ public static ChatMessage fromJson(JsonReader jsonReader) throws IOException { } else if ("version".equals(fieldName)) { deserializedChatMessage.version = reader.getString(); } else if ("createdOn".equals(fieldName)) { - deserializedChatMessage.createdOn - = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); + deserializedChatMessage.createdOn = reader + .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString())); } else if ("content".equals(fieldName)) { deserializedChatMessage.content = ChatMessageContent.fromJson(reader); } else if ("senderDisplayName".equals(fieldName)) { @@ -371,11 +378,11 @@ public static ChatMessage fromJson(JsonReader jsonReader) throws IOException { deserializedChatMessage.senderCommunicationIdentifier = CommunicationIdentifierModel.fromJson(reader); } else if ("deletedOn".equals(fieldName)) { - deserializedChatMessage.deletedOn - = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); + deserializedChatMessage.deletedOn = reader + .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString())); } else if ("editedOn".equals(fieldName)) { - deserializedChatMessage.editedOn - = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); + deserializedChatMessage.editedOn = reader + .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString())); } else if ("metadata".equals(fieldName)) { Map metadata = reader.readMap(reader1 -> reader1.getString()); deserializedChatMessage.metadata = metadata; diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageContent.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageContent.java index 938c5cd9bf13..90fab2fa68ab 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageContent.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageContent.java @@ -38,7 +38,9 @@ public final class ChatMessageContent implements JsonSerializable attachments; /* - * Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from kind and rawId, at most one further property may be set which must match the kind enum value. + * Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an + * Azure communication user. This model is polymorphic: Apart from kind and rawId, at most one further property may + * be set which must match the kind enum value. */ private CommunicationIdentifierModel initiatorCommunicationIdentifier; diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageReadReceipt.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageReadReceipt.java index 2000e9026e19..f32af20a9ce9 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageReadReceipt.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatMessageReadReceipt.java @@ -5,6 +5,7 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; +import com.azure.core.util.CoreUtils; import com.azure.json.JsonReader; import com.azure.json.JsonSerializable; import com.azure.json.JsonToken; @@ -19,7 +20,9 @@ @Fluent public final class ChatMessageReadReceipt implements JsonSerializable { /* - * Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from kind and rawId, at most one further property may be set which must match the kind enum value. + * Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an + * Azure communication user. This model is polymorphic: Apart from kind and rawId, at most one further property may + * be set which must match the kind enum value. */ private CommunicationIdentifierModel senderCommunicationIdentifier; @@ -141,8 +144,8 @@ public static ChatMessageReadReceipt fromJson(JsonReader jsonReader) throws IOEx } else if ("chatMessageId".equals(fieldName)) { deserializedChatMessageReadReceipt.chatMessageId = reader.getString(); } else if ("readOn".equals(fieldName)) { - deserializedChatMessageReadReceipt.readOn - = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); + deserializedChatMessageReadReceipt.readOn = reader + .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString())); } else { reader.skipChildren(); } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatParticipant.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatParticipant.java index 4b040bfd354f..22a2817b2548 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatParticipant.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatParticipant.java @@ -5,6 +5,7 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; +import com.azure.core.util.CoreUtils; import com.azure.json.JsonReader; import com.azure.json.JsonSerializable; import com.azure.json.JsonToken; @@ -19,7 +20,9 @@ @Fluent public final class ChatParticipant implements JsonSerializable { /* - * Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an Azure communication user. This model is polymorphic: Apart from kind and rawId, at most one further property may be set which must match the kind enum value. + * Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an + * Azure communication user. This model is polymorphic: Apart from kind and rawId, at most one further property may + * be set which must match the kind enum value. */ private CommunicationIdentifierModel communicationIdentifier; @@ -29,7 +32,8 @@ public final class ChatParticipant implements JsonSerializable private String displayName; /* - * Time from which the chat history is shared with the participant. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. + * Time from which the chat history is shared with the participant. The timestamp is in RFC3339 format: + * `yyyy-MM-ddTHH:mm:ssZ`. */ private OffsetDateTime shareHistoryTime; @@ -141,8 +145,8 @@ public static ChatParticipant fromJson(JsonReader jsonReader) throws IOException } else if ("displayName".equals(fieldName)) { deserializedChatParticipant.displayName = reader.getString(); } else if ("shareHistoryTime".equals(fieldName)) { - deserializedChatParticipant.shareHistoryTime - = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); + deserializedChatParticipant.shareHistoryTime = reader + .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString())); } else { reader.skipChildren(); } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadProperties.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadProperties.java index 5c7e22194354..b095c16c1d9b 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadProperties.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/implementation/models/ChatThreadProperties.java @@ -5,6 +5,7 @@ package com.azure.communication.chat.implementation.models; import com.azure.core.annotation.Fluent; +import com.azure.core.util.CoreUtils; import com.azure.json.JsonReader; import com.azure.json.JsonSerializable; import com.azure.json.JsonToken; @@ -34,7 +35,9 @@ public final class ChatThreadProperties implements JsonSerializable OffsetDateTime.parse(nonNullReader.getString())); + deserializedChatThreadProperties.createdOn = reader + .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString())); } else if ("createdByCommunicationIdentifier".equals(fieldName)) { deserializedChatThreadProperties.createdByCommunicationIdentifier = CommunicationIdentifierModel.fromJson(reader); } else if ("deletedOn".equals(fieldName)) { - deserializedChatThreadProperties.deletedOn - = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); + deserializedChatThreadProperties.deletedOn = reader + .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString())); } else { reader.skipChildren(); } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadItem.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadItem.java index 20b851de8d15..444896453f99 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadItem.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/ChatThreadItem.java @@ -5,6 +5,7 @@ package com.azure.communication.chat.models; import com.azure.core.annotation.Fluent; +import com.azure.core.util.CoreUtils; import com.azure.json.JsonReader; import com.azure.json.JsonSerializable; import com.azure.json.JsonToken; @@ -34,7 +35,8 @@ public final class ChatThreadItem implements JsonSerializable { private OffsetDateTime deletedOn; /* - * The timestamp when the last message arrived at the server. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`. + * The timestamp when the last message arrived at the server. The timestamp is in RFC3339 format: + * `yyyy-MM-ddTHH:mm:ssZ`. */ private OffsetDateTime lastMessageReceivedOn; @@ -150,11 +152,11 @@ public static ChatThreadItem fromJson(JsonReader jsonReader) throws IOException } else if ("topic".equals(fieldName)) { deserializedChatThreadItem.topic = reader.getString(); } else if ("deletedOn".equals(fieldName)) { - deserializedChatThreadItem.deletedOn - = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); + deserializedChatThreadItem.deletedOn = reader + .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString())); } else if ("lastMessageReceivedOn".equals(fieldName)) { - deserializedChatThreadItem.lastMessageReceivedOn - = reader.getNullable(nonNullReader -> OffsetDateTime.parse(nonNullReader.getString())); + deserializedChatThreadItem.lastMessageReceivedOn = reader + .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString())); } else { reader.skipChildren(); } diff --git a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageOptions.java b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageOptions.java index 004e83ef3318..cd10d2f2e07c 100644 --- a/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageOptions.java +++ b/sdk/communication/azure-communication-chat/src/main/java/com/azure/communication/chat/models/SendChatMessageOptions.java @@ -23,7 +23,8 @@ public final class SendChatMessageOptions implements JsonSerializable { /* - * The display name of the typing notification sender. This property is used to populate sender name for push notifications. + * The display name of the typing notification sender. This property is used to populate sender name for push + * notifications. */ private String senderDisplayName; diff --git a/sdk/communication/azure-communication-chat/swagger/README.md b/sdk/communication/azure-communication-chat/swagger/README.md index 512409d70cb0..b4a23a12bf00 100644 --- a/sdk/communication/azure-communication-chat/swagger/README.md +++ b/sdk/communication/azure-communication-chat/swagger/README.md @@ -36,7 +36,7 @@ To update generated files for chat service, run the following command ```yaml tag: package-chat-2024-03-07 -use: '@autorest/java@4.1.29' +use: '@autorest/java@4.1.33' require: - https://raw.githubusercontent.com/Azure/azure-rest-api-specs/72d4c8cae964a12dc27ad4684b0bddf493225338/specification/communication/data-plane/Chat/readme.md java: true From f22d89bcd9d029d5c0b6f692dd10a29266466b3e Mon Sep 17 00:00:00 2001 From: anuchandy Date: Tue, 9 Jul 2024 17:31:44 -0700 Subject: [PATCH 7/7] update revapi.json for azure json migration --- .../src/main/resources/revapi/revapi.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/eng/code-quality-reports/src/main/resources/revapi/revapi.json b/eng/code-quality-reports/src/main/resources/revapi/revapi.json index 1f45584be3b7..c97bacacd98f 100644 --- a/eng/code-quality-reports/src/main/resources/revapi/revapi.json +++ b/eng/code-quality-reports/src/main/resources/revapi/revapi.json @@ -492,6 +492,13 @@ "old" : ".*? com\\.azure\\.communication\\.callautomation\\.models.*", "new" : ".*? com\\.azure\\.communication\\.callautomation\\.models.*", "justification": "Migration to azure-json" + }, + { + "regex": true, + "code" : "java\\.annotation\\.removed", + "old" : ".*? com\\.azure\\.communication\\.chat\\.models.*", + "new" : ".*? com\\.azure\\.communication\\.chat\\.models.*", + "justification": "Migration to azure-json" } ] }