Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed jackson.databind #43427

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
package com.azure.communication.callautomation.models;

import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Base64;

import com.azure.core.annotation.Fluent;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.azure.json.JsonProviders;
import com.azure.json.JsonWriter;

/** The PlaySource model. */
@Fluent
Expand Down Expand Up @@ -79,38 +83,70 @@ OutStreamingData setStopAudio() {
* Get the streaming data for outbound
* @param audioData the audioData to set
* @return the string of outstreaming data
* @throws IOException when failed to serilize the data
*
*/
public static String getStreamingDataForOutbound(byte[] audioData) {
public static String getStreamingDataForOutbound(byte[] audioData) throws IOException {
OutStreamingData data = new OutStreamingData(MediaKind.AUDIO_DATA);
data.setAudioData(audioData);

ObjectMapper objectMapper = new ObjectMapper();
try {
String serializedData = objectMapper.writeValueAsString(data);
return serializedData;
} catch (IOException e) {
e.printStackTrace();
return null;
}
return serializeOutStreamingData(data);
}

/**
* Get the stop audiofor outbound
* @return the string of outstreaming data
* @throws IOException throws exception when failed to serialize
*
*/
public static String getStopAudioForOutbound() {
public static String getStopAudioForOutbound() throws IOException {
OutStreamingData data = new OutStreamingData(MediaKind.STOP_AUDIO);
data.setStopAudio();
return serializeOutStreamingData(data);
}

/**
* serilize the outstreaming data
* @param data Outstreaming data
* @return string
* @throws IOException throws exception when fails to serialize
*/
private static String serializeOutStreamingData(OutStreamingData data) throws IOException {
Writer json = new StringWriter();
try (JsonWriter jsonWriter = JsonProviders.createWriter(json)) {
// JsonWriter automatically flushes on close.
data.toJson(jsonWriter);
}

ObjectMapper objectMapper = new ObjectMapper();
try {
String serializedData = objectMapper.writeValueAsString(data);
return serializedData;
} catch (IOException e) {
e.printStackTrace();
return null;
return json.toString();
}

/**
* convert to json
* @param jsonWriter json writer
* @return return json writeer
* @throws IOException hrows exception when fails to serialize
*/
private JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
jsonWriter.writeStringField("kind", this.kind.toString());

if (this.audioData != null) {
jsonWriter.writeFieldName("audioData");
jsonWriter.writeStartObject();
jsonWriter.writeRawField("data", Base64.getEncoder().encodeToString(this.audioData.getData()));
jsonWriter.writeNullField("timestamp");
jsonWriter.writeNullField("participant");
jsonWriter.writeBooleanField("isSilent", this.audioData.isSilent());
jsonWriter.writeEndObject();
}

if (this.stopAudio != null) {
jsonWriter.writeRawField("stopAudio", "{}");
} else {
jsonWriter.writeNullField("stopAudio");
}

jsonWriter.writeEndObject();
return jsonWriter;
}
}
Loading