com.sinch.sdk.domains.voice.adapters.converters.ControlDtoConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sinch-sdk-java Show documentation
Show all versions of sinch-sdk-java Show documentation
SDK providing a Java API for the Sinch REST APIs.
package com.sinch.sdk.domains.voice.adapters.converters;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.sinch.sdk.core.exceptions.ApiMappingException;
import com.sinch.sdk.core.utils.databind.Mapper;
import com.sinch.sdk.domains.voice.models.requests.Control;
import com.sinch.sdk.domains.voice.models.requests.ControlUrl;
import com.sinch.sdk.domains.voice.models.svaml.SVAMLControl;
import java.util.logging.Logger;
public class ControlDtoConverter {
private static final Logger LOGGER = Logger.getLogger(SVAMLActionDtoConverter.class.getName());
public static String convert(Control client) {
if (null == client) {
return null;
}
String dto;
if (client instanceof SVAMLControl) {
SVAMLControl value = (SVAMLControl) client;
dto = convertControlToEscapedJSON(value);
} else if (client instanceof ControlUrl) {
ControlUrl value = (ControlUrl) client;
dto = value.getURL();
} else {
LOGGER.severe(String.format("Unexpected class '%s'", client.getClass()));
dto = client.toString();
}
return dto;
}
private static String convertControlToEscapedJSON(SVAMLControl client) {
try {
return Mapper.getInstance().writeValueAsString(CallsDtoConverter.convert(client));
} catch (JsonProcessingException e) {
throw new ApiMappingException(client.toString(), e);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy