diff --git a/src/main/java/com/twilio/twiml/FaxResponse.java b/src/main/java/com/twilio/twiml/FaxResponse.java index 30b7ee8604..1e386891be 100644 --- a/src/main/java/com/twilio/twiml/FaxResponse.java +++ b/src/main/java/com/twilio/twiml/FaxResponse.java @@ -7,11 +7,16 @@ package com.twilio.twiml; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.twilio.twiml.TwiMLException; import com.twilio.twiml.fax.Receive; /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = FaxResponse.Builder.class) public class FaxResponse extends TwiML { /** * For XML Serialization/Deserialization @@ -31,9 +36,24 @@ private FaxResponse(Builder b) { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a FaxResponse.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Receive") public Builder receive(Receive receive) { this.children.add(receive); return this; diff --git a/src/main/java/com/twilio/twiml/MessagingResponse.java b/src/main/java/com/twilio/twiml/MessagingResponse.java index 580c7dc70b..059ca90e8b 100644 --- a/src/main/java/com/twilio/twiml/MessagingResponse.java +++ b/src/main/java/com/twilio/twiml/MessagingResponse.java @@ -7,12 +7,17 @@ package com.twilio.twiml; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.twilio.twiml.TwiMLException; import com.twilio.twiml.messaging.Message; import com.twilio.twiml.messaging.Redirect; /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = MessagingResponse.Builder.class) public class MessagingResponse extends TwiML { /** * For XML Serialization/Deserialization @@ -32,9 +37,24 @@ private MessagingResponse(Builder b) { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a MessagingResponse.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Message") public Builder message(Message message) { this.children.add(message); return this; @@ -43,6 +63,7 @@ public Builder message(Message message) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Redirect") public Builder redirect(Redirect redirect) { this.children.add(redirect); return this; diff --git a/src/main/java/com/twilio/twiml/VoiceResponse.java b/src/main/java/com/twilio/twiml/VoiceResponse.java index d8bbb94b97..a607b4745d 100644 --- a/src/main/java/com/twilio/twiml/VoiceResponse.java +++ b/src/main/java/com/twilio/twiml/VoiceResponse.java @@ -7,6 +7,10 @@ package com.twilio.twiml; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.twilio.twiml.TwiMLException; import com.twilio.twiml.voice.Connect; import com.twilio.twiml.voice.Dial; import com.twilio.twiml.voice.Echo; @@ -31,6 +35,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = VoiceResponse.Builder.class) public class VoiceResponse extends TwiML { /** * For XML Serialization/Deserialization @@ -50,9 +55,24 @@ private VoiceResponse(Builder b) { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a VoiceResponse.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Connect") public Builder connect(Connect connect) { this.children.add(connect); return this; @@ -61,6 +81,7 @@ public Builder connect(Connect connect) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Dial") public Builder dial(Dial dial) { this.children.add(dial); return this; @@ -69,6 +90,7 @@ public Builder dial(Dial dial) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Echo") public Builder echo(Echo echo) { this.children.add(echo); return this; @@ -77,6 +99,7 @@ public Builder echo(Echo echo) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Enqueue") public Builder enqueue(Enqueue enqueue) { this.children.add(enqueue); return this; @@ -85,6 +108,7 @@ public Builder enqueue(Enqueue enqueue) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Gather") public Builder gather(Gather gather) { this.children.add(gather); return this; @@ -93,6 +117,7 @@ public Builder gather(Gather gather) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Hangup") public Builder hangup(Hangup hangup) { this.children.add(hangup); return this; @@ -101,6 +126,7 @@ public Builder hangup(Hangup hangup) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Leave") public Builder leave(Leave leave) { this.children.add(leave); return this; @@ -109,6 +135,7 @@ public Builder leave(Leave leave) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Pause") public Builder pause(Pause pause) { this.children.add(pause); return this; @@ -117,6 +144,7 @@ public Builder pause(Pause pause) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Play") public Builder play(Play play) { this.children.add(play); return this; @@ -125,6 +153,7 @@ public Builder play(Play play) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Queue") public Builder queue(Queue queue) { this.children.add(queue); return this; @@ -133,6 +162,7 @@ public Builder queue(Queue queue) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Record") public Builder record(Record record) { this.children.add(record); return this; @@ -141,6 +171,7 @@ public Builder record(Record record) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Redirect") public Builder redirect(Redirect redirect) { this.children.add(redirect); return this; @@ -149,6 +180,7 @@ public Builder redirect(Redirect redirect) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Reject") public Builder reject(Reject reject) { this.children.add(reject); return this; @@ -157,6 +189,7 @@ public Builder reject(Reject reject) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Say") public Builder say(Say say) { this.children.add(say); return this; @@ -165,6 +198,7 @@ public Builder say(Say say) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Sms") public Builder sms(Sms sms) { this.children.add(sms); return this; @@ -173,6 +207,7 @@ public Builder sms(Sms sms) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Pay") public Builder pay(Pay pay) { this.children.add(pay); return this; @@ -181,6 +216,7 @@ public Builder pay(Pay pay) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Prompt") public Builder prompt(Prompt prompt) { this.children.add(prompt); return this; @@ -189,6 +225,7 @@ public Builder prompt(Prompt prompt) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Start") public Builder start(Start start) { this.children.add(start); return this; @@ -197,6 +234,7 @@ public Builder start(Start start) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Stop") public Builder stop(Stop stop) { this.children.add(stop); return this; @@ -205,6 +243,7 @@ public Builder stop(Stop stop) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Refer") public Builder refer(Refer refer) { this.children.add(refer); return this; diff --git a/src/main/java/com/twilio/twiml/fax/Receive.java b/src/main/java/com/twilio/twiml/fax/Receive.java index 1510f68076..288d6ffbe8 100644 --- a/src/main/java/com/twilio/twiml/fax/Receive.java +++ b/src/main/java/com/twilio/twiml/fax/Receive.java @@ -7,9 +7,13 @@ package com.twilio.twiml.fax; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.converter.Promoter; import com.twilio.http.HttpMethod; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.net.URI; import java.util.HashMap; @@ -18,6 +22,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Receive.Builder.class) public class Receive extends TwiML { public enum MediaType { APPLICATION_PDF("application/pdf"), @@ -152,6 +157,20 @@ public Boolean isStoreMedia() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Receive.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private URI action; private HttpMethod method; private Receive.MediaType mediaType; @@ -161,6 +180,7 @@ public static class Builder extends TwiML.Builder { /** * Receive action URL */ + @JacksonXmlProperty(isAttribute = true, localName = "action") public Builder action(URI action) { this.action = action; return this; @@ -177,6 +197,7 @@ public Builder action(String action) { /** * Receive action URL method */ + @JacksonXmlProperty(isAttribute = true, localName = "method") public Builder method(HttpMethod method) { this.method = method; return this; @@ -185,6 +206,7 @@ public Builder method(HttpMethod method) { /** * The media type used to store media in the fax media store */ + @JacksonXmlProperty(isAttribute = true, localName = "mediaType") public Builder mediaType(Receive.MediaType mediaType) { this.mediaType = mediaType; return this; @@ -193,6 +215,7 @@ public Builder mediaType(Receive.MediaType mediaType) { /** * What size to interpret received pages as */ + @JacksonXmlProperty(isAttribute = true, localName = "pageSize") public Builder pageSize(Receive.PageSize pageSize) { this.pageSize = pageSize; return this; @@ -201,6 +224,7 @@ public Builder pageSize(Receive.PageSize pageSize) { /** * Whether or not to store received media in the fax media store */ + @JacksonXmlProperty(isAttribute = true, localName = "storeMedia") public Builder storeMedia(Boolean storeMedia) { this.storeMedia = storeMedia; return this; diff --git a/src/main/java/com/twilio/twiml/messaging/Body.java b/src/main/java/com/twilio/twiml/messaging/Body.java index 04eb5a9c15..4ac9fe19e3 100644 --- a/src/main/java/com/twilio/twiml/messaging/Body.java +++ b/src/main/java/com/twilio/twiml/messaging/Body.java @@ -7,11 +7,15 @@ package com.twilio.twiml.messaging; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Body.Builder.class) public class Body extends TwiML { private final String message; @@ -52,6 +56,20 @@ public String getMessage() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Body.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private String message; /** @@ -61,6 +79,12 @@ public Builder(String message) { this.message = message; } + /** + * Create a {@code } (for XML deserialization) + */ + private Builder() { + } + /** * Create and return resulting {@code } element */ diff --git a/src/main/java/com/twilio/twiml/messaging/Media.java b/src/main/java/com/twilio/twiml/messaging/Media.java index 339ee6a0af..e8c54d6346 100644 --- a/src/main/java/com/twilio/twiml/messaging/Media.java +++ b/src/main/java/com/twilio/twiml/messaging/Media.java @@ -7,14 +7,18 @@ package com.twilio.twiml.messaging; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.converter.Promoter; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.net.URI; /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Media.Builder.class) public class Media extends TwiML { private final URI url; @@ -55,6 +59,20 @@ public URI getUrl() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Media.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private URI url; /** @@ -71,6 +89,12 @@ public Builder(String url) { this.url = Promoter.uriFromString(url); } + /** + * Create a {@code } (for XML deserialization) + */ + private Builder() { + } + /** * Create and return resulting {@code } element */ diff --git a/src/main/java/com/twilio/twiml/messaging/Message.java b/src/main/java/com/twilio/twiml/messaging/Message.java index ae35905d55..d36597c0b6 100644 --- a/src/main/java/com/twilio/twiml/messaging/Message.java +++ b/src/main/java/com/twilio/twiml/messaging/Message.java @@ -7,9 +7,13 @@ package com.twilio.twiml.messaging; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.converter.Promoter; import com.twilio.http.HttpMethod; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.net.URI; import java.util.HashMap; @@ -18,6 +22,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Message.Builder.class) public class Message extends TwiML { private final String to; private final String from; @@ -141,6 +146,20 @@ public String getBody() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Message.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private String to; private String from; private URI action; @@ -164,6 +183,7 @@ public Builder() { /** * Phone Number to send Message to */ + @JacksonXmlProperty(isAttribute = true, localName = "to") public Builder to(String to) { this.to = to; return this; @@ -172,6 +192,7 @@ public Builder to(String to) { /** * Phone Number to send Message from */ + @JacksonXmlProperty(isAttribute = true, localName = "from") public Builder from(String from) { this.from = from; return this; @@ -180,6 +201,7 @@ public Builder from(String from) { /** * Action URL */ + @JacksonXmlProperty(isAttribute = true, localName = "action") public Builder action(URI action) { this.action = action; return this; @@ -196,6 +218,7 @@ public Builder action(String action) { /** * Action URL Method */ + @JacksonXmlProperty(isAttribute = true, localName = "method") public Builder method(HttpMethod method) { this.method = method; return this; @@ -204,6 +227,7 @@ public Builder method(HttpMethod method) { /** * Status callback URL. Deprecated in favor of action. */ + @JacksonXmlProperty(isAttribute = true, localName = "statusCallback") public Builder statusCallback(URI statusCallback) { this.statusCallback = statusCallback; return this; @@ -220,6 +244,7 @@ public Builder statusCallback(String statusCallback) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Body") public Builder body(Body body) { this.children.add(body); return this; @@ -228,6 +253,7 @@ public Builder body(Body body) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Media") public Builder media(Media media) { this.children.add(media); return this; diff --git a/src/main/java/com/twilio/twiml/messaging/Redirect.java b/src/main/java/com/twilio/twiml/messaging/Redirect.java index f6a042081b..f55fd879e3 100644 --- a/src/main/java/com/twilio/twiml/messaging/Redirect.java +++ b/src/main/java/com/twilio/twiml/messaging/Redirect.java @@ -7,9 +7,13 @@ package com.twilio.twiml.messaging; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.converter.Promoter; import com.twilio.http.HttpMethod; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.net.URI; import java.util.HashMap; @@ -18,6 +22,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Redirect.Builder.class) public class Redirect extends TwiML { private final HttpMethod method; private final URI url; @@ -85,6 +90,20 @@ public URI getUrl() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Redirect.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private HttpMethod method; private URI url; @@ -102,9 +121,16 @@ public Builder(String url) { this.url = Promoter.uriFromString(url); } + /** + * Create a {@code } (for XML deserialization) + */ + private Builder() { + } + /** * Redirect URL method */ + @JacksonXmlProperty(isAttribute = true, localName = "method") public Builder method(HttpMethod method) { this.method = method; return this; diff --git a/src/main/java/com/twilio/twiml/voice/Autopilot.java b/src/main/java/com/twilio/twiml/voice/Autopilot.java index f0405f0428..e894bdb4d3 100644 --- a/src/main/java/com/twilio/twiml/voice/Autopilot.java +++ b/src/main/java/com/twilio/twiml/voice/Autopilot.java @@ -7,11 +7,15 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Autopilot.Builder.class) public class Autopilot extends TwiML { private final String name; @@ -52,6 +56,20 @@ public String getName() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Autopilot.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private String name; /** @@ -61,6 +79,12 @@ public Builder(String name) { this.name = name; } + /** + * Create a {@code } (for XML deserialization) + */ + private Builder() { + } + /** * Create and return resulting {@code } element */ diff --git a/src/main/java/com/twilio/twiml/voice/Client.java b/src/main/java/com/twilio/twiml/voice/Client.java index 9f2038ac35..dc8e3d8e50 100644 --- a/src/main/java/com/twilio/twiml/voice/Client.java +++ b/src/main/java/com/twilio/twiml/voice/Client.java @@ -7,9 +7,13 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.converter.Promoter; import com.twilio.http.HttpMethod; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.net.URI; import java.util.HashMap; @@ -20,6 +24,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Client.Builder.class) public class Client extends TwiML { public enum Event { INITIATED("initiated"), @@ -172,6 +177,20 @@ public String getIdentity() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Client.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private URI url; private HttpMethod method; private List statusCallbackEvent; @@ -195,6 +214,7 @@ public Builder() { /** * Client URL */ + @JacksonXmlProperty(isAttribute = true, localName = "url") public Builder url(URI url) { this.url = url; return this; @@ -211,6 +231,7 @@ public Builder url(String url) { /** * Client URL Method */ + @JacksonXmlProperty(isAttribute = true, localName = "method") public Builder method(HttpMethod method) { this.method = method; return this; @@ -219,6 +240,7 @@ public Builder method(HttpMethod method) { /** * Events to trigger status callback */ + @JacksonXmlProperty(isAttribute = true, localName = "statusCallbackEvent") public Builder statusCallbackEvents(List statusCallbackEvent) { this.statusCallbackEvent = statusCallbackEvent; return this; @@ -235,6 +257,7 @@ public Builder statusCallbackEvents(Client.Event statusCallbackEvent) { /** * Status Callback URL */ + @JacksonXmlProperty(isAttribute = true, localName = "statusCallback") public Builder statusCallback(URI statusCallback) { this.statusCallback = statusCallback; return this; @@ -251,6 +274,7 @@ public Builder statusCallback(String statusCallback) { /** * Status Callback URL Method */ + @JacksonXmlProperty(isAttribute = true, localName = "statusCallbackMethod") public Builder statusCallbackMethod(HttpMethod statusCallbackMethod) { this.statusCallbackMethod = statusCallbackMethod; return this; @@ -259,6 +283,7 @@ public Builder statusCallbackMethod(HttpMethod statusCallbackMethod) { /** * Client identity */ + @JacksonXmlProperty(isAttribute = true, localName = "identity") public Builder identity(String identity) { this.identity = identity; return this; @@ -267,6 +292,7 @@ public Builder identity(String identity) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Identity") public Builder identity(Identity identity) { this.children.add(identity); return this; @@ -275,6 +301,7 @@ public Builder identity(Identity identity) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Parameter") public Builder parameter(Parameter parameter) { this.children.add(parameter); return this; diff --git a/src/main/java/com/twilio/twiml/voice/Conference.java b/src/main/java/com/twilio/twiml/voice/Conference.java index 64a1d94a04..f663c41bb4 100644 --- a/src/main/java/com/twilio/twiml/voice/Conference.java +++ b/src/main/java/com/twilio/twiml/voice/Conference.java @@ -7,9 +7,13 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.converter.Promoter; import com.twilio.http.HttpMethod; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.net.URI; import java.util.HashMap; @@ -20,6 +24,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Conference.Builder.class) public class Conference extends TwiML { public enum Beep { TRUE("true"), @@ -499,6 +504,20 @@ public String getName() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Conference.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private Boolean muted; private Conference.Beep beep; private Boolean startConferenceOnEnter; @@ -528,9 +547,16 @@ public Builder(String name) { this.name = name; } + /** + * Create a {@code } (for XML deserialization) + */ + private Builder() { + } + /** * Join the conference muted */ + @JacksonXmlProperty(isAttribute = true, localName = "muted") public Builder muted(Boolean muted) { this.muted = muted; return this; @@ -539,6 +565,7 @@ public Builder muted(Boolean muted) { /** * Play beep when joining */ + @JacksonXmlProperty(isAttribute = true, localName = "beep") public Builder beep(Conference.Beep beep) { this.beep = beep; return this; @@ -547,6 +574,7 @@ public Builder beep(Conference.Beep beep) { /** * Start the conference on enter */ + @JacksonXmlProperty(isAttribute = true, localName = "startConferenceOnEnter") public Builder startConferenceOnEnter(Boolean startConferenceOnEnter) { this.startConferenceOnEnter = startConferenceOnEnter; return this; @@ -555,6 +583,7 @@ public Builder startConferenceOnEnter(Boolean startConferenceOnEnter) { /** * End the conferenceon exit */ + @JacksonXmlProperty(isAttribute = true, localName = "endConferenceOnExit") public Builder endConferenceOnExit(Boolean endConferenceOnExit) { this.endConferenceOnExit = endConferenceOnExit; return this; @@ -563,6 +592,7 @@ public Builder endConferenceOnExit(Boolean endConferenceOnExit) { /** * Wait URL */ + @JacksonXmlProperty(isAttribute = true, localName = "waitUrl") public Builder waitUrl(URI waitUrl) { this.waitUrl = waitUrl; return this; @@ -579,6 +609,7 @@ public Builder waitUrl(String waitUrl) { /** * Wait URL method */ + @JacksonXmlProperty(isAttribute = true, localName = "waitMethod") public Builder waitMethod(HttpMethod waitMethod) { this.waitMethod = waitMethod; return this; @@ -587,6 +618,7 @@ public Builder waitMethod(HttpMethod waitMethod) { /** * Maximum number of participants */ + @JacksonXmlProperty(isAttribute = true, localName = "maxParticipants") public Builder maxParticipants(Integer maxParticipants) { this.maxParticipants = maxParticipants; return this; @@ -595,6 +627,7 @@ public Builder maxParticipants(Integer maxParticipants) { /** * Record the conference */ + @JacksonXmlProperty(isAttribute = true, localName = "record") public Builder record(Conference.Record record) { this.record = record; return this; @@ -603,6 +636,7 @@ public Builder record(Conference.Record record) { /** * Conference region */ + @JacksonXmlProperty(isAttribute = true, localName = "region") public Builder region(Conference.Region region) { this.region = region; return this; @@ -611,6 +645,7 @@ public Builder region(Conference.Region region) { /** * Call coach */ + @JacksonXmlProperty(isAttribute = true, localName = "coach") public Builder coach(String coach) { this.coach = coach; return this; @@ -619,6 +654,7 @@ public Builder coach(String coach) { /** * Trim the conference recording */ + @JacksonXmlProperty(isAttribute = true, localName = "trim") public Builder trim(Conference.Trim trim) { this.trim = trim; return this; @@ -627,6 +663,7 @@ public Builder trim(Conference.Trim trim) { /** * Events to call status callback URL */ + @JacksonXmlProperty(isAttribute = true, localName = "statusCallbackEvent") public Builder statusCallbackEvents(List statusCallbackEvent) { this.statusCallbackEvent = statusCallbackEvent; return this; @@ -643,6 +680,7 @@ public Builder statusCallbackEvents(Conference.Event statusCallbackEvent) { /** * Status callback URL */ + @JacksonXmlProperty(isAttribute = true, localName = "statusCallback") public Builder statusCallback(URI statusCallback) { this.statusCallback = statusCallback; return this; @@ -659,6 +697,7 @@ public Builder statusCallback(String statusCallback) { /** * Status callback URL method */ + @JacksonXmlProperty(isAttribute = true, localName = "statusCallbackMethod") public Builder statusCallbackMethod(HttpMethod statusCallbackMethod) { this.statusCallbackMethod = statusCallbackMethod; return this; @@ -667,6 +706,7 @@ public Builder statusCallbackMethod(HttpMethod statusCallbackMethod) { /** * Recording status callback URL */ + @JacksonXmlProperty(isAttribute = true, localName = "recordingStatusCallback") public Builder recordingStatusCallback(URI recordingStatusCallback) { this.recordingStatusCallback = recordingStatusCallback; return this; @@ -683,6 +723,7 @@ public Builder recordingStatusCallback(String recordingStatusCallback) { /** * Recording status callback URL method */ + @JacksonXmlProperty(isAttribute = true, localName = "recordingStatusCallbackMethod") public Builder recordingStatusCallbackMethod(HttpMethod recordingStatusCallbackMethod) { this.recordingStatusCallbackMethod = recordingStatusCallbackMethod; return this; @@ -691,6 +732,7 @@ public Builder recordingStatusCallbackMethod(HttpMethod recordingStatusCallbackM /** * Recording status callback events */ + @JacksonXmlProperty(isAttribute = true, localName = "recordingStatusCallbackEvent") public Builder recordingStatusCallbackEvents(List recordingStatusCallbackEvent) { this.recordingStatusCallbackEvent = recordingStatusCallbackEvent; return this; @@ -707,6 +749,7 @@ public Builder recordingStatusCallbackEvents(Conference.RecordingEvent recording /** * Event callback URL */ + @JacksonXmlProperty(isAttribute = true, localName = "eventCallbackUrl") public Builder eventCallbackUrl(URI eventCallbackUrl) { this.eventCallbackUrl = eventCallbackUrl; return this; @@ -723,6 +766,7 @@ public Builder eventCallbackUrl(String eventCallbackUrl) { /** * Size of jitter buffer for participant */ + @JacksonXmlProperty(isAttribute = true, localName = "jitterBufferSize") public Builder jitterBufferSize(Conference.JitterBufferSize jitterBufferSize) { this.jitterBufferSize = jitterBufferSize; return this; @@ -731,6 +775,7 @@ public Builder jitterBufferSize(Conference.JitterBufferSize jitterBufferSize) { /** * A label for participant */ + @JacksonXmlProperty(isAttribute = true, localName = "participantLabel") public Builder participantLabel(String participantLabel) { this.participantLabel = participantLabel; return this; diff --git a/src/main/java/com/twilio/twiml/voice/Connect.java b/src/main/java/com/twilio/twiml/voice/Connect.java index c977725c7a..8bf1840428 100644 --- a/src/main/java/com/twilio/twiml/voice/Connect.java +++ b/src/main/java/com/twilio/twiml/voice/Connect.java @@ -7,9 +7,13 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.converter.Promoter; import com.twilio.http.HttpMethod; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.net.URI; import java.util.HashMap; @@ -18,6 +22,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Connect.Builder.class) public class Connect extends TwiML { private final URI action; private final HttpMethod method; @@ -79,12 +84,27 @@ public HttpMethod getMethod() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Connect.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private URI action; private HttpMethod method; /** * Action URL */ + @JacksonXmlProperty(isAttribute = true, localName = "action") public Builder action(URI action) { this.action = action; return this; @@ -101,6 +121,7 @@ public Builder action(String action) { /** * Action URL method */ + @JacksonXmlProperty(isAttribute = true, localName = "method") public Builder method(HttpMethod method) { this.method = method; return this; @@ -109,6 +130,7 @@ public Builder method(HttpMethod method) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Room") public Builder room(Room room) { this.children.add(room); return this; @@ -117,6 +139,7 @@ public Builder room(Room room) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Autopilot") public Builder autopilot(Autopilot autopilot) { this.children.add(autopilot); return this; @@ -125,6 +148,7 @@ public Builder autopilot(Autopilot autopilot) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Stream") public Builder stream(Stream stream) { this.children.add(stream); return this; @@ -133,6 +157,7 @@ public Builder stream(Stream stream) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "VirtualAgent") public Builder virtualAgent(VirtualAgent virtualAgent) { this.children.add(virtualAgent); return this; diff --git a/src/main/java/com/twilio/twiml/voice/Dial.java b/src/main/java/com/twilio/twiml/voice/Dial.java index 8fbc73095c..52df4ad8df 100644 --- a/src/main/java/com/twilio/twiml/voice/Dial.java +++ b/src/main/java/com/twilio/twiml/voice/Dial.java @@ -7,9 +7,13 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.converter.Promoter; import com.twilio.http.HttpMethod; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.net.URI; import java.util.HashMap; @@ -20,6 +24,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Dial.Builder.class) public class Dial extends TwiML { public enum Trim { TRIM_SILENCE("trim-silence"), @@ -449,6 +454,20 @@ public String getNumber() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Dial.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private URI action; private HttpMethod method; private Integer timeout; @@ -484,6 +503,7 @@ public Builder() { /** * Action URL */ + @JacksonXmlProperty(isAttribute = true, localName = "action") public Builder action(URI action) { this.action = action; return this; @@ -500,6 +520,7 @@ public Builder action(String action) { /** * Action URL method */ + @JacksonXmlProperty(isAttribute = true, localName = "method") public Builder method(HttpMethod method) { this.method = method; return this; @@ -508,6 +529,7 @@ public Builder method(HttpMethod method) { /** * Time to wait for answer */ + @JacksonXmlProperty(isAttribute = true, localName = "timeout") public Builder timeout(Integer timeout) { this.timeout = timeout; return this; @@ -516,6 +538,7 @@ public Builder timeout(Integer timeout) { /** * Hangup call on star press */ + @JacksonXmlProperty(isAttribute = true, localName = "hangupOnStar") public Builder hangupOnStar(Boolean hangupOnStar) { this.hangupOnStar = hangupOnStar; return this; @@ -524,6 +547,7 @@ public Builder hangupOnStar(Boolean hangupOnStar) { /** * Max time length */ + @JacksonXmlProperty(isAttribute = true, localName = "timeLimit") public Builder timeLimit(Integer timeLimit) { this.timeLimit = timeLimit; return this; @@ -532,6 +556,7 @@ public Builder timeLimit(Integer timeLimit) { /** * Caller ID to display */ + @JacksonXmlProperty(isAttribute = true, localName = "callerId") public Builder callerId(String callerId) { this.callerId = callerId; return this; @@ -540,6 +565,7 @@ public Builder callerId(String callerId) { /** * Record the call */ + @JacksonXmlProperty(isAttribute = true, localName = "record") public Builder record(Dial.Record record) { this.record = record; return this; @@ -548,6 +574,7 @@ public Builder record(Dial.Record record) { /** * Trim the recording */ + @JacksonXmlProperty(isAttribute = true, localName = "trim") public Builder trim(Dial.Trim trim) { this.trim = trim; return this; @@ -556,6 +583,7 @@ public Builder trim(Dial.Trim trim) { /** * Recording status callback URL */ + @JacksonXmlProperty(isAttribute = true, localName = "recordingStatusCallback") public Builder recordingStatusCallback(URI recordingStatusCallback) { this.recordingStatusCallback = recordingStatusCallback; return this; @@ -572,6 +600,7 @@ public Builder recordingStatusCallback(String recordingStatusCallback) { /** * Recording status callback URL method */ + @JacksonXmlProperty(isAttribute = true, localName = "recordingStatusCallbackMethod") public Builder recordingStatusCallbackMethod(HttpMethod recordingStatusCallbackMethod) { this.recordingStatusCallbackMethod = recordingStatusCallbackMethod; return this; @@ -580,6 +609,7 @@ public Builder recordingStatusCallbackMethod(HttpMethod recordingStatusCallbackM /** * Recording status callback events */ + @JacksonXmlProperty(isAttribute = true, localName = "recordingStatusCallbackEvent") public Builder recordingStatusCallbackEvents(List recordingStatusCallbackEvent) { this.recordingStatusCallbackEvent = recordingStatusCallbackEvent; return this; @@ -597,6 +627,7 @@ public Builder recordingStatusCallbackEvents(Dial.RecordingEvent recordingStatus * Preserve the ringing behavior of the inbound call until the Dialed call picks * up */ + @JacksonXmlProperty(isAttribute = true, localName = "answerOnBridge") public Builder answerOnBridge(Boolean answerOnBridge) { this.answerOnBridge = answerOnBridge; return this; @@ -606,6 +637,7 @@ public Builder answerOnBridge(Boolean answerOnBridge) { * Ringtone allows you to override the ringback tone that Twilio will play back * to the caller while executing the Dial */ + @JacksonXmlProperty(isAttribute = true, localName = "ringTone") public Builder ringTone(Dial.RingTone ringTone) { this.ringTone = ringTone; return this; @@ -614,6 +646,7 @@ public Builder ringTone(Dial.RingTone ringTone) { /** * To indicate which audio track should be recorded */ + @JacksonXmlProperty(isAttribute = true, localName = "recordingTrack") public Builder recordingTrack(Dial.RecordingTrack recordingTrack) { this.recordingTrack = recordingTrack; return this; @@ -624,6 +657,7 @@ public Builder recordingTrack(Dial.RecordingTrack recordingTrack) { * the other (sequential) or dial all at once (parallel). Default is false, * parallel */ + @JacksonXmlProperty(isAttribute = true, localName = "sequential") public Builder sequential(Boolean sequential) { this.sequential = sequential; return this; @@ -632,6 +666,7 @@ public Builder sequential(Boolean sequential) { /** * Webhook that will receive future SIP REFER requests */ + @JacksonXmlProperty(isAttribute = true, localName = "referUrl") public Builder referUrl(URI referUrl) { this.referUrl = referUrl; return this; @@ -648,6 +683,7 @@ public Builder referUrl(String referUrl) { /** * The HTTP method to use for the refer Webhook */ + @JacksonXmlProperty(isAttribute = true, localName = "referMethod") public Builder referMethod(HttpMethod referMethod) { this.referMethod = referMethod; return this; @@ -656,6 +692,7 @@ public Builder referMethod(HttpMethod referMethod) { /** * Phone number to dial */ + @JacksonXmlProperty(isAttribute = true, localName = "number") public Builder number(String number) { this.number = number; return this; @@ -664,6 +701,7 @@ public Builder number(String number) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Client") public Builder client(Client client) { this.children.add(client); return this; @@ -672,6 +710,7 @@ public Builder client(Client client) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Conference") public Builder conference(Conference conference) { this.children.add(conference); return this; @@ -680,6 +719,7 @@ public Builder conference(Conference conference) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Number") public Builder number(Number number) { this.children.add(number); return this; @@ -688,6 +728,7 @@ public Builder number(Number number) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Queue") public Builder queue(Queue queue) { this.children.add(queue); return this; @@ -696,6 +737,7 @@ public Builder queue(Queue queue) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Sim") public Builder sim(Sim sim) { this.children.add(sim); return this; @@ -704,6 +746,7 @@ public Builder sim(Sim sim) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Sip") public Builder sip(Sip sip) { this.children.add(sip); return this; diff --git a/src/main/java/com/twilio/twiml/voice/Echo.java b/src/main/java/com/twilio/twiml/voice/Echo.java index ff6ebe2270..497b328290 100644 --- a/src/main/java/com/twilio/twiml/voice/Echo.java +++ b/src/main/java/com/twilio/twiml/voice/Echo.java @@ -7,7 +7,9 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; /** * TwiML wrapper for {@code } @@ -31,6 +33,20 @@ private Echo(Builder b) { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Echo.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + /** * Create and return resulting {@code } element */ diff --git a/src/main/java/com/twilio/twiml/voice/Enqueue.java b/src/main/java/com/twilio/twiml/voice/Enqueue.java index 87aa87da11..8979e0e149 100644 --- a/src/main/java/com/twilio/twiml/voice/Enqueue.java +++ b/src/main/java/com/twilio/twiml/voice/Enqueue.java @@ -7,9 +7,13 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.converter.Promoter; import com.twilio.http.HttpMethod; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.net.URI; import java.util.HashMap; @@ -18,6 +22,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Enqueue.Builder.class) public class Enqueue extends TwiML { private final URI action; private final HttpMethod method; @@ -141,6 +146,20 @@ public String getName() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Enqueue.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private URI action; private HttpMethod method; private URI waitUrl; @@ -164,6 +183,7 @@ public Builder() { /** * Action URL */ + @JacksonXmlProperty(isAttribute = true, localName = "action") public Builder action(URI action) { this.action = action; return this; @@ -180,6 +200,7 @@ public Builder action(String action) { /** * Action URL method */ + @JacksonXmlProperty(isAttribute = true, localName = "method") public Builder method(HttpMethod method) { this.method = method; return this; @@ -188,6 +209,7 @@ public Builder method(HttpMethod method) { /** * Wait URL */ + @JacksonXmlProperty(isAttribute = true, localName = "waitUrl") public Builder waitUrl(URI waitUrl) { this.waitUrl = waitUrl; return this; @@ -204,6 +226,7 @@ public Builder waitUrl(String waitUrl) { /** * Wait URL method */ + @JacksonXmlProperty(isAttribute = true, localName = "waitUrlMethod") public Builder waitUrlMethod(HttpMethod waitUrlMethod) { this.waitUrlMethod = waitUrlMethod; return this; @@ -212,6 +235,7 @@ public Builder waitUrlMethod(HttpMethod waitUrlMethod) { /** * TaskRouter Workflow SID */ + @JacksonXmlProperty(isAttribute = true, localName = "workflowSid") public Builder workflowSid(String workflowSid) { this.workflowSid = workflowSid; return this; @@ -220,6 +244,7 @@ public Builder workflowSid(String workflowSid) { /** * Friendly name */ + @JacksonXmlProperty(isAttribute = true, localName = "name") public Builder name(String name) { this.name = name; return this; @@ -228,6 +253,7 @@ public Builder name(String name) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Task") public Builder task(Task task) { this.children.add(task); return this; diff --git a/src/main/java/com/twilio/twiml/voice/Gather.java b/src/main/java/com/twilio/twiml/voice/Gather.java index 442b395a01..7ee09ea274 100644 --- a/src/main/java/com/twilio/twiml/voice/Gather.java +++ b/src/main/java/com/twilio/twiml/voice/Gather.java @@ -7,9 +7,13 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.converter.Promoter; import com.twilio.http.HttpMethod; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.net.URI; import java.util.HashMap; @@ -20,6 +24,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Gather.Builder.class) public class Gather extends TwiML { public enum Input { DTMF("dtmf"), @@ -493,6 +498,20 @@ public Boolean isEnhanced() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Gather.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private List input; private URI action; private HttpMethod method; @@ -515,6 +534,7 @@ public static class Builder extends TwiML.Builder { /** * Input type Twilio should accept */ + @JacksonXmlProperty(isAttribute = true, localName = "input") public Builder inputs(List input) { this.input = input; return this; @@ -531,6 +551,7 @@ public Builder inputs(Gather.Input input) { /** * Action URL */ + @JacksonXmlProperty(isAttribute = true, localName = "action") public Builder action(URI action) { this.action = action; return this; @@ -547,6 +568,7 @@ public Builder action(String action) { /** * Action URL method */ + @JacksonXmlProperty(isAttribute = true, localName = "method") public Builder method(HttpMethod method) { this.method = method; return this; @@ -555,6 +577,7 @@ public Builder method(HttpMethod method) { /** * Time to wait to gather input */ + @JacksonXmlProperty(isAttribute = true, localName = "timeout") public Builder timeout(Integer timeout) { this.timeout = timeout; return this; @@ -564,6 +587,7 @@ public Builder timeout(Integer timeout) { * Time to wait to gather speech input and it should be either auto or a * positive integer. */ + @JacksonXmlProperty(isAttribute = true, localName = "speechTimeout") public Builder speechTimeout(String speechTimeout) { this.speechTimeout = speechTimeout; return this; @@ -572,6 +596,7 @@ public Builder speechTimeout(String speechTimeout) { /** * Max allowed time for speech input */ + @JacksonXmlProperty(isAttribute = true, localName = "maxSpeechTime") public Builder maxSpeechTime(Integer maxSpeechTime) { this.maxSpeechTime = maxSpeechTime; return this; @@ -580,6 +605,7 @@ public Builder maxSpeechTime(Integer maxSpeechTime) { /** * Profanity Filter on speech */ + @JacksonXmlProperty(isAttribute = true, localName = "profanityFilter") public Builder profanityFilter(Boolean profanityFilter) { this.profanityFilter = profanityFilter; return this; @@ -588,6 +614,7 @@ public Builder profanityFilter(Boolean profanityFilter) { /** * Finish gather on key */ + @JacksonXmlProperty(isAttribute = true, localName = "finishOnKey") public Builder finishOnKey(String finishOnKey) { this.finishOnKey = finishOnKey; return this; @@ -596,6 +623,7 @@ public Builder finishOnKey(String finishOnKey) { /** * Number of digits to collect */ + @JacksonXmlProperty(isAttribute = true, localName = "numDigits") public Builder numDigits(Integer numDigits) { this.numDigits = numDigits; return this; @@ -604,6 +632,7 @@ public Builder numDigits(Integer numDigits) { /** * Partial result callback URL */ + @JacksonXmlProperty(isAttribute = true, localName = "partialResultCallback") public Builder partialResultCallback(URI partialResultCallback) { this.partialResultCallback = partialResultCallback; return this; @@ -620,6 +649,7 @@ public Builder partialResultCallback(String partialResultCallback) { /** * Partial result callback URL method */ + @JacksonXmlProperty(isAttribute = true, localName = "partialResultCallbackMethod") public Builder partialResultCallbackMethod(HttpMethod partialResultCallbackMethod) { this.partialResultCallbackMethod = partialResultCallbackMethod; return this; @@ -628,6 +658,7 @@ public Builder partialResultCallbackMethod(HttpMethod partialResultCallbackMetho /** * Language to use */ + @JacksonXmlProperty(isAttribute = true, localName = "language") public Builder language(Gather.Language language) { this.language = language; return this; @@ -636,6 +667,7 @@ public Builder language(Gather.Language language) { /** * Speech recognition hints */ + @JacksonXmlProperty(isAttribute = true, localName = "hints") public Builder hints(String hints) { this.hints = hints; return this; @@ -644,6 +676,7 @@ public Builder hints(String hints) { /** * Stop playing media upon speech */ + @JacksonXmlProperty(isAttribute = true, localName = "bargeIn") public Builder bargeIn(Boolean bargeIn) { this.bargeIn = bargeIn; return this; @@ -652,6 +685,7 @@ public Builder bargeIn(Boolean bargeIn) { /** * Allow debug for gather */ + @JacksonXmlProperty(isAttribute = true, localName = "debug") public Builder debug(Boolean debug) { this.debug = debug; return this; @@ -660,6 +694,7 @@ public Builder debug(Boolean debug) { /** * Force webhook to the action URL event if there is no input */ + @JacksonXmlProperty(isAttribute = true, localName = "actionOnEmptyResult") public Builder actionOnEmptyResult(Boolean actionOnEmptyResult) { this.actionOnEmptyResult = actionOnEmptyResult; return this; @@ -668,6 +703,7 @@ public Builder actionOnEmptyResult(Boolean actionOnEmptyResult) { /** * Specify the model that is best suited for your use case */ + @JacksonXmlProperty(isAttribute = true, localName = "speechModel") public Builder speechModel(Gather.SpeechModel speechModel) { this.speechModel = speechModel; return this; @@ -676,6 +712,7 @@ public Builder speechModel(Gather.SpeechModel speechModel) { /** * Use enhanced speech model */ + @JacksonXmlProperty(isAttribute = true, localName = "enhanced") public Builder enhanced(Boolean enhanced) { this.enhanced = enhanced; return this; @@ -684,6 +721,7 @@ public Builder enhanced(Boolean enhanced) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Say") public Builder say(Say say) { this.children.add(say); return this; @@ -692,6 +730,7 @@ public Builder say(Say say) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Pause") public Builder pause(Pause pause) { this.children.add(pause); return this; @@ -700,6 +739,7 @@ public Builder pause(Pause pause) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Play") public Builder play(Play play) { this.children.add(play); return this; diff --git a/src/main/java/com/twilio/twiml/voice/Hangup.java b/src/main/java/com/twilio/twiml/voice/Hangup.java index 4f2a9b781b..14c9e199bf 100644 --- a/src/main/java/com/twilio/twiml/voice/Hangup.java +++ b/src/main/java/com/twilio/twiml/voice/Hangup.java @@ -7,7 +7,9 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; /** * TwiML wrapper for {@code } @@ -31,6 +33,20 @@ private Hangup(Builder b) { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Hangup.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + /** * Create and return resulting {@code } element */ diff --git a/src/main/java/com/twilio/twiml/voice/Identity.java b/src/main/java/com/twilio/twiml/voice/Identity.java index 425d4f1b04..7e3432192d 100644 --- a/src/main/java/com/twilio/twiml/voice/Identity.java +++ b/src/main/java/com/twilio/twiml/voice/Identity.java @@ -7,11 +7,15 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Identity.Builder.class) public class Identity extends TwiML { private final String clientIdentity; @@ -52,6 +56,20 @@ public String getClientIdentity() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Identity.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private String clientIdentity; /** @@ -61,6 +79,12 @@ public Builder(String clientIdentity) { this.clientIdentity = clientIdentity; } + /** + * Create a {@code } (for XML deserialization) + */ + private Builder() { + } + /** * Create and return resulting {@code } element */ diff --git a/src/main/java/com/twilio/twiml/voice/Leave.java b/src/main/java/com/twilio/twiml/voice/Leave.java index d09c3311c5..af4a5526a6 100644 --- a/src/main/java/com/twilio/twiml/voice/Leave.java +++ b/src/main/java/com/twilio/twiml/voice/Leave.java @@ -7,7 +7,9 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; /** * TwiML wrapper for {@code } @@ -31,6 +33,20 @@ private Leave(Builder b) { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Leave.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + /** * Create and return resulting {@code } element */ diff --git a/src/main/java/com/twilio/twiml/voice/Number.java b/src/main/java/com/twilio/twiml/voice/Number.java index 811642dea3..794c736008 100644 --- a/src/main/java/com/twilio/twiml/voice/Number.java +++ b/src/main/java/com/twilio/twiml/voice/Number.java @@ -7,9 +7,13 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.converter.Promoter; import com.twilio.http.HttpMethod; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.net.URI; import java.util.HashMap; @@ -20,6 +24,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Number.Builder.class) public class Number extends TwiML { public enum Event { INITIATED("initiated"), @@ -200,6 +205,20 @@ public com.twilio.type.PhoneNumber getPhoneNumber() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Number.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private String sendDigits; private URI url; private HttpMethod method; @@ -223,9 +242,16 @@ public Builder(String phoneNumber) { this.phoneNumber = Promoter.phoneNumberFromString(phoneNumber); } + /** + * Create a {@code } (for XML deserialization) + */ + private Builder() { + } + /** * DTMF tones to play when the call is answered */ + @JacksonXmlProperty(isAttribute = true, localName = "sendDigits") public Builder sendDigits(String sendDigits) { this.sendDigits = sendDigits; return this; @@ -234,6 +260,7 @@ public Builder sendDigits(String sendDigits) { /** * TwiML URL */ + @JacksonXmlProperty(isAttribute = true, localName = "url") public Builder url(URI url) { this.url = url; return this; @@ -250,6 +277,7 @@ public Builder url(String url) { /** * TwiML URL method */ + @JacksonXmlProperty(isAttribute = true, localName = "method") public Builder method(HttpMethod method) { this.method = method; return this; @@ -258,6 +286,7 @@ public Builder method(HttpMethod method) { /** * Events to call status callback */ + @JacksonXmlProperty(isAttribute = true, localName = "statusCallbackEvent") public Builder statusCallbackEvents(List statusCallbackEvent) { this.statusCallbackEvent = statusCallbackEvent; return this; @@ -274,6 +303,7 @@ public Builder statusCallbackEvents(Number.Event statusCallbackEvent) { /** * Status callback URL */ + @JacksonXmlProperty(isAttribute = true, localName = "statusCallback") public Builder statusCallback(URI statusCallback) { this.statusCallback = statusCallback; return this; @@ -290,6 +320,7 @@ public Builder statusCallback(String statusCallback) { /** * Status callback URL method */ + @JacksonXmlProperty(isAttribute = true, localName = "statusCallbackMethod") public Builder statusCallbackMethod(HttpMethod statusCallbackMethod) { this.statusCallbackMethod = statusCallbackMethod; return this; @@ -298,6 +329,7 @@ public Builder statusCallbackMethod(HttpMethod statusCallbackMethod) { /** * BYOC trunk SID (Beta) */ + @JacksonXmlProperty(isAttribute = true, localName = "byoc") public Builder byoc(String byoc) { this.byoc = byoc; return this; diff --git a/src/main/java/com/twilio/twiml/voice/Parameter.java b/src/main/java/com/twilio/twiml/voice/Parameter.java index 6420aa591f..4879db5e2a 100644 --- a/src/main/java/com/twilio/twiml/voice/Parameter.java +++ b/src/main/java/com/twilio/twiml/voice/Parameter.java @@ -7,7 +7,11 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.util.HashMap; import java.util.Map; @@ -15,6 +19,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Parameter.Builder.class) public class Parameter extends TwiML { private final String name; private final String value; @@ -76,12 +81,27 @@ public String getValue() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Parameter.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private String name; private String value; /** * The name of the custom parameter */ + @JacksonXmlProperty(isAttribute = true, localName = "name") public Builder name(String name) { this.name = name; return this; @@ -90,6 +110,7 @@ public Builder name(String name) { /** * The value of the custom parameter */ + @JacksonXmlProperty(isAttribute = true, localName = "value") public Builder value(String value) { this.value = value; return this; diff --git a/src/main/java/com/twilio/twiml/voice/Pause.java b/src/main/java/com/twilio/twiml/voice/Pause.java index 0fb9b05ed4..45b1e49ee5 100644 --- a/src/main/java/com/twilio/twiml/voice/Pause.java +++ b/src/main/java/com/twilio/twiml/voice/Pause.java @@ -7,7 +7,11 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.util.HashMap; import java.util.Map; @@ -15,6 +19,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Pause.Builder.class) public class Pause extends TwiML { private final Integer length; @@ -62,11 +67,26 @@ public Integer getLength() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Pause.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private Integer length; /** * Length in seconds to pause */ + @JacksonXmlProperty(isAttribute = true, localName = "length") public Builder length(Integer length) { this.length = length; return this; diff --git a/src/main/java/com/twilio/twiml/voice/Pay.java b/src/main/java/com/twilio/twiml/voice/Pay.java index 447400ae57..32aa70fcc6 100644 --- a/src/main/java/com/twilio/twiml/voice/Pay.java +++ b/src/main/java/com/twilio/twiml/voice/Pay.java @@ -7,8 +7,12 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.converter.Promoter; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.net.URI; import java.util.HashMap; @@ -19,6 +23,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Pay.Builder.class) public class Pay extends TwiML { public enum Input { DTMF("dtmf"); @@ -449,6 +454,20 @@ public Pay.Language getLanguage() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Pay.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private Pay.Input input; private URI action; private Pay.BankAccountType bankAccountType; @@ -471,6 +490,7 @@ public static class Builder extends TwiML.Builder { /** * Input type Twilio should accept */ + @JacksonXmlProperty(isAttribute = true, localName = "input") public Builder input(Pay.Input input) { this.input = input; return this; @@ -479,6 +499,7 @@ public Builder input(Pay.Input input) { /** * Action URL */ + @JacksonXmlProperty(isAttribute = true, localName = "action") public Builder action(URI action) { this.action = action; return this; @@ -497,6 +518,7 @@ public Builder action(String action) { * be provided and value should be set to ach-debit. defaults to * consumer-checking */ + @JacksonXmlProperty(isAttribute = true, localName = "bankAccountType") public Builder bankAccountType(Pay.BankAccountType bankAccountType) { this.bankAccountType = bankAccountType; return this; @@ -505,6 +527,7 @@ public Builder bankAccountType(Pay.BankAccountType bankAccountType) { /** * Status callback URL */ + @JacksonXmlProperty(isAttribute = true, localName = "statusCallback") public Builder statusCallback(URI statusCallback) { this.statusCallback = statusCallback; return this; @@ -521,6 +544,7 @@ public Builder statusCallback(String statusCallback) { /** * Status callback method */ + @JacksonXmlProperty(isAttribute = true, localName = "statusCallbackMethod") public Builder statusCallbackMethod(Pay.StatusCallbackMethod statusCallbackMethod) { this.statusCallbackMethod = statusCallbackMethod; return this; @@ -529,6 +553,7 @@ public Builder statusCallbackMethod(Pay.StatusCallbackMethod statusCallbackMetho /** * Time to wait to gather input */ + @JacksonXmlProperty(isAttribute = true, localName = "timeout") public Builder timeout(Integer timeout) { this.timeout = timeout; return this; @@ -537,6 +562,7 @@ public Builder timeout(Integer timeout) { /** * Maximum number of allowed retries when gathering input */ + @JacksonXmlProperty(isAttribute = true, localName = "maxAttempts") public Builder maxAttempts(Integer maxAttempts) { this.maxAttempts = maxAttempts; return this; @@ -545,6 +571,7 @@ public Builder maxAttempts(Integer maxAttempts) { /** * Prompt for security code */ + @JacksonXmlProperty(isAttribute = true, localName = "securityCode") public Builder securityCode(Boolean securityCode) { this.securityCode = securityCode; return this; @@ -553,6 +580,7 @@ public Builder securityCode(Boolean securityCode) { /** * Prompt for postal code and it should be true/false or default postal code */ + @JacksonXmlProperty(isAttribute = true, localName = "postalCode") public Builder postalCode(String postalCode) { this.postalCode = postalCode; return this; @@ -561,6 +589,7 @@ public Builder postalCode(String postalCode) { /** * Prompt for minimum postal code length */ + @JacksonXmlProperty(isAttribute = true, localName = "minPostalCodeLength") public Builder minPostalCodeLength(Integer minPostalCodeLength) { this.minPostalCodeLength = minPostalCodeLength; return this; @@ -569,6 +598,7 @@ public Builder minPostalCodeLength(Integer minPostalCodeLength) { /** * Unique name for payment connector */ + @JacksonXmlProperty(isAttribute = true, localName = "paymentConnector") public Builder paymentConnector(String paymentConnector) { this.paymentConnector = paymentConnector; return this; @@ -577,6 +607,7 @@ public Builder paymentConnector(String paymentConnector) { /** * Payment method to be used. defaults to credit-card */ + @JacksonXmlProperty(isAttribute = true, localName = "paymentMethod") public Builder paymentMethod(Pay.PaymentMethod paymentMethod) { this.paymentMethod = paymentMethod; return this; @@ -585,6 +616,7 @@ public Builder paymentMethod(Pay.PaymentMethod paymentMethod) { /** * Type of token */ + @JacksonXmlProperty(isAttribute = true, localName = "tokenType") public Builder tokenType(Pay.TokenType tokenType) { this.tokenType = tokenType; return this; @@ -594,6 +626,7 @@ public Builder tokenType(Pay.TokenType tokenType) { * Amount to process. If value is greater than 0 then make the payment else * create a payment token */ + @JacksonXmlProperty(isAttribute = true, localName = "chargeAmount") public Builder chargeAmount(String chargeAmount) { this.chargeAmount = chargeAmount; return this; @@ -602,6 +635,7 @@ public Builder chargeAmount(String chargeAmount) { /** * Currency of the amount attribute */ + @JacksonXmlProperty(isAttribute = true, localName = "currency") public Builder currency(String currency) { this.currency = currency; return this; @@ -610,6 +644,7 @@ public Builder currency(String currency) { /** * Details regarding the payment */ + @JacksonXmlProperty(isAttribute = true, localName = "description") public Builder description(String description) { this.description = description; return this; @@ -618,6 +653,7 @@ public Builder description(String description) { /** * Comma separated accepted card types */ + @JacksonXmlProperty(isAttribute = true, localName = "validCardTypes") public Builder validCardTypes(List validCardTypes) { this.validCardTypes = validCardTypes; return this; @@ -634,6 +670,7 @@ public Builder validCardTypes(Pay.ValidCardTypes validCardTypes) { /** * Language to use */ + @JacksonXmlProperty(isAttribute = true, localName = "language") public Builder language(Pay.Language language) { this.language = language; return this; @@ -642,6 +679,7 @@ public Builder language(Pay.Language language) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Prompt") public Builder prompt(Prompt prompt) { this.children.add(prompt); return this; @@ -650,6 +688,7 @@ public Builder prompt(Prompt prompt) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Parameter") public Builder parameter(Parameter parameter) { this.children.add(parameter); return this; diff --git a/src/main/java/com/twilio/twiml/voice/Play.java b/src/main/java/com/twilio/twiml/voice/Play.java index a95e857e4d..87f3a83626 100644 --- a/src/main/java/com/twilio/twiml/voice/Play.java +++ b/src/main/java/com/twilio/twiml/voice/Play.java @@ -7,8 +7,12 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.converter.Promoter; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.net.URI; import java.util.HashMap; @@ -17,6 +21,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Play.Builder.class) public class Play extends TwiML { private final Integer loop; private final String digits; @@ -98,6 +103,20 @@ public URI getUrl() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Play.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private Integer loop; private String digits; private URI url; @@ -125,6 +144,7 @@ public Builder() { /** * Times to loop media */ + @JacksonXmlProperty(isAttribute = true, localName = "loop") public Builder loop(Integer loop) { this.loop = loop; return this; @@ -133,6 +153,7 @@ public Builder loop(Integer loop) { /** * Play DTMF tones for digits */ + @JacksonXmlProperty(isAttribute = true, localName = "digits") public Builder digits(String digits) { this.digits = digits; return this; @@ -141,6 +162,7 @@ public Builder digits(String digits) { /** * Media URL */ + @JacksonXmlProperty(isAttribute = true, localName = "url") public Builder url(URI url) { this.url = url; return this; diff --git a/src/main/java/com/twilio/twiml/voice/Prompt.java b/src/main/java/com/twilio/twiml/voice/Prompt.java index b4d2e751a0..a56276dab8 100644 --- a/src/main/java/com/twilio/twiml/voice/Prompt.java +++ b/src/main/java/com/twilio/twiml/voice/Prompt.java @@ -7,8 +7,12 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.converter.Promoter; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.util.HashMap; import java.util.Iterator; @@ -18,6 +22,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Prompt.Builder.class) public class Prompt extends TwiML { public enum For { PAYMENT_CARD_NUMBER("payment-card-number"), @@ -204,6 +209,20 @@ protected String getAttemptsAsString() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Prompt.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private Prompt.For for_; private List errorType; private List cardType; @@ -212,6 +231,7 @@ public static class Builder extends TwiML.Builder { /** * Name of the payment source data element */ + @JacksonXmlProperty(isAttribute = true, localName = "for") public Builder for_(Prompt.For for_) { this.for_ = for_; return this; @@ -220,6 +240,7 @@ public Builder for_(Prompt.For for_) { /** * Type of error */ + @JacksonXmlProperty(isAttribute = true, localName = "errorType") public Builder errorTypes(List errorType) { this.errorType = errorType; return this; @@ -236,6 +257,7 @@ public Builder errorTypes(Prompt.ErrorType errorType) { /** * Type of the credit card */ + @JacksonXmlProperty(isAttribute = true, localName = "cardType") public Builder cardTypes(List cardType) { this.cardType = cardType; return this; @@ -252,6 +274,7 @@ public Builder cardTypes(Prompt.CardType cardType) { /** * Current attempt count */ + @JacksonXmlProperty(isAttribute = true, localName = "attempt") public Builder attempts(List attempt) { this.attempt = attempt; return this; @@ -268,6 +291,7 @@ public Builder attempts(Integer attempt) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Say") public Builder say(Say say) { this.children.add(say); return this; @@ -276,6 +300,7 @@ public Builder say(Say say) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Play") public Builder play(Play play) { this.children.add(play); return this; @@ -284,6 +309,7 @@ public Builder play(Play play) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Pause") public Builder pause(Pause pause) { this.children.add(pause); return this; diff --git a/src/main/java/com/twilio/twiml/voice/Queue.java b/src/main/java/com/twilio/twiml/voice/Queue.java index 64c3f8ed59..b4dd4e94ae 100644 --- a/src/main/java/com/twilio/twiml/voice/Queue.java +++ b/src/main/java/com/twilio/twiml/voice/Queue.java @@ -7,9 +7,13 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.converter.Promoter; import com.twilio.http.HttpMethod; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.net.URI; import java.util.HashMap; @@ -18,6 +22,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Queue.Builder.class) public class Queue extends TwiML { private final URI url; private final HttpMethod method; @@ -127,6 +132,20 @@ public String getName() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Queue.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private URI url; private HttpMethod method; private String reservationSid; @@ -140,9 +159,16 @@ public Builder(String name) { this.name = name; } + /** + * Create a {@code } (for XML deserialization) + */ + private Builder() { + } + /** * Action URL */ + @JacksonXmlProperty(isAttribute = true, localName = "url") public Builder url(URI url) { this.url = url; return this; @@ -159,6 +185,7 @@ public Builder url(String url) { /** * Action URL method */ + @JacksonXmlProperty(isAttribute = true, localName = "method") public Builder method(HttpMethod method) { this.method = method; return this; @@ -167,6 +194,7 @@ public Builder method(HttpMethod method) { /** * TaskRouter Reservation SID */ + @JacksonXmlProperty(isAttribute = true, localName = "reservationSid") public Builder reservationSid(String reservationSid) { this.reservationSid = reservationSid; return this; @@ -175,6 +203,7 @@ public Builder reservationSid(String reservationSid) { /** * TaskRouter Activity SID */ + @JacksonXmlProperty(isAttribute = true, localName = "postWorkActivitySid") public Builder postWorkActivitySid(String postWorkActivitySid) { this.postWorkActivitySid = postWorkActivitySid; return this; diff --git a/src/main/java/com/twilio/twiml/voice/Record.java b/src/main/java/com/twilio/twiml/voice/Record.java index 98f4dc28d9..2059369460 100644 --- a/src/main/java/com/twilio/twiml/voice/Record.java +++ b/src/main/java/com/twilio/twiml/voice/Record.java @@ -7,9 +7,13 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.converter.Promoter; import com.twilio.http.HttpMethod; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.net.URI; import java.util.HashMap; @@ -20,6 +24,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Record.Builder.class) public class Record extends TwiML { public enum Trim { TRIM_SILENCE("trim-silence"), @@ -264,6 +269,20 @@ public URI getTranscribeCallback() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Record.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private URI action; private HttpMethod method; private Integer timeout; @@ -280,6 +299,7 @@ public static class Builder extends TwiML.Builder { /** * Action URL */ + @JacksonXmlProperty(isAttribute = true, localName = "action") public Builder action(URI action) { this.action = action; return this; @@ -296,6 +316,7 @@ public Builder action(String action) { /** * Action URL method */ + @JacksonXmlProperty(isAttribute = true, localName = "method") public Builder method(HttpMethod method) { this.method = method; return this; @@ -304,6 +325,7 @@ public Builder method(HttpMethod method) { /** * Timeout to begin recording */ + @JacksonXmlProperty(isAttribute = true, localName = "timeout") public Builder timeout(Integer timeout) { this.timeout = timeout; return this; @@ -312,6 +334,7 @@ public Builder timeout(Integer timeout) { /** * Finish recording on key */ + @JacksonXmlProperty(isAttribute = true, localName = "finishOnKey") public Builder finishOnKey(String finishOnKey) { this.finishOnKey = finishOnKey; return this; @@ -320,6 +343,7 @@ public Builder finishOnKey(String finishOnKey) { /** * Max time to record in seconds */ + @JacksonXmlProperty(isAttribute = true, localName = "maxLength") public Builder maxLength(Integer maxLength) { this.maxLength = maxLength; return this; @@ -328,6 +352,7 @@ public Builder maxLength(Integer maxLength) { /** * Play beep */ + @JacksonXmlProperty(isAttribute = true, localName = "playBeep") public Builder playBeep(Boolean playBeep) { this.playBeep = playBeep; return this; @@ -336,6 +361,7 @@ public Builder playBeep(Boolean playBeep) { /** * Trim the recording */ + @JacksonXmlProperty(isAttribute = true, localName = "trim") public Builder trim(Record.Trim trim) { this.trim = trim; return this; @@ -344,6 +370,7 @@ public Builder trim(Record.Trim trim) { /** * Status callback URL */ + @JacksonXmlProperty(isAttribute = true, localName = "recordingStatusCallback") public Builder recordingStatusCallback(URI recordingStatusCallback) { this.recordingStatusCallback = recordingStatusCallback; return this; @@ -360,6 +387,7 @@ public Builder recordingStatusCallback(String recordingStatusCallback) { /** * Status callback URL method */ + @JacksonXmlProperty(isAttribute = true, localName = "recordingStatusCallbackMethod") public Builder recordingStatusCallbackMethod(HttpMethod recordingStatusCallbackMethod) { this.recordingStatusCallbackMethod = recordingStatusCallbackMethod; return this; @@ -368,6 +396,7 @@ public Builder recordingStatusCallbackMethod(HttpMethod recordingStatusCallbackM /** * Recording status callback events */ + @JacksonXmlProperty(isAttribute = true, localName = "recordingStatusCallbackEvent") public Builder recordingStatusCallbackEvents(List recordingStatusCallbackEvent) { this.recordingStatusCallbackEvent = recordingStatusCallbackEvent; return this; @@ -384,6 +413,7 @@ public Builder recordingStatusCallbackEvents(Record.RecordingEvent recordingStat /** * Transcribe the recording */ + @JacksonXmlProperty(isAttribute = true, localName = "transcribe") public Builder transcribe(Boolean transcribe) { this.transcribe = transcribe; return this; @@ -392,6 +422,7 @@ public Builder transcribe(Boolean transcribe) { /** * Transcribe callback URL */ + @JacksonXmlProperty(isAttribute = true, localName = "transcribeCallback") public Builder transcribeCallback(URI transcribeCallback) { this.transcribeCallback = transcribeCallback; return this; diff --git a/src/main/java/com/twilio/twiml/voice/Redirect.java b/src/main/java/com/twilio/twiml/voice/Redirect.java index 2a63fe71e2..d0ef7da570 100644 --- a/src/main/java/com/twilio/twiml/voice/Redirect.java +++ b/src/main/java/com/twilio/twiml/voice/Redirect.java @@ -7,9 +7,13 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.converter.Promoter; import com.twilio.http.HttpMethod; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.net.URI; import java.util.HashMap; @@ -18,6 +22,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Redirect.Builder.class) public class Redirect extends TwiML { private final HttpMethod method; private final URI url; @@ -85,6 +90,20 @@ public URI getUrl() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Redirect.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private HttpMethod method; private URI url; @@ -102,9 +121,16 @@ public Builder(String url) { this.url = Promoter.uriFromString(url); } + /** + * Create a {@code } (for XML deserialization) + */ + private Builder() { + } + /** * Redirect URL method */ + @JacksonXmlProperty(isAttribute = true, localName = "method") public Builder method(HttpMethod method) { this.method = method; return this; diff --git a/src/main/java/com/twilio/twiml/voice/Refer.java b/src/main/java/com/twilio/twiml/voice/Refer.java index 94b2ecc9b5..c57c6156a8 100644 --- a/src/main/java/com/twilio/twiml/voice/Refer.java +++ b/src/main/java/com/twilio/twiml/voice/Refer.java @@ -7,9 +7,13 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.converter.Promoter; import com.twilio.http.HttpMethod; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.net.URI; import java.util.HashMap; @@ -18,6 +22,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Refer.Builder.class) public class Refer extends TwiML { private final URI action; private final HttpMethod method; @@ -79,12 +84,27 @@ public HttpMethod getMethod() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Refer.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private URI action; private HttpMethod method; /** * Action URL */ + @JacksonXmlProperty(isAttribute = true, localName = "action") public Builder action(URI action) { this.action = action; return this; @@ -101,6 +121,7 @@ public Builder action(String action) { /** * Action URL method */ + @JacksonXmlProperty(isAttribute = true, localName = "method") public Builder method(HttpMethod method) { this.method = method; return this; @@ -109,6 +130,7 @@ public Builder method(HttpMethod method) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Sip") public Builder sip(ReferSip referSip) { this.children.add(referSip); return this; diff --git a/src/main/java/com/twilio/twiml/voice/ReferSip.java b/src/main/java/com/twilio/twiml/voice/ReferSip.java index a0496c4184..0154178608 100644 --- a/src/main/java/com/twilio/twiml/voice/ReferSip.java +++ b/src/main/java/com/twilio/twiml/voice/ReferSip.java @@ -7,14 +7,18 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.converter.Promoter; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.net.URI; /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = ReferSip.Builder.class) public class ReferSip extends TwiML { private final URI sipUrl; @@ -55,6 +59,20 @@ public URI getSipUrl() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a ReferSip.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private URI sipUrl; /** @@ -71,6 +89,12 @@ public Builder(String sipUrl) { this.sipUrl = Promoter.uriFromString(sipUrl); } + /** + * Create a {@code } (for XML deserialization) + */ + private Builder() { + } + /** * Create and return resulting {@code } element */ diff --git a/src/main/java/com/twilio/twiml/voice/Reject.java b/src/main/java/com/twilio/twiml/voice/Reject.java index 76625446aa..f2f44c89c9 100644 --- a/src/main/java/com/twilio/twiml/voice/Reject.java +++ b/src/main/java/com/twilio/twiml/voice/Reject.java @@ -7,7 +7,11 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.util.HashMap; import java.util.Map; @@ -15,6 +19,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Reject.Builder.class) public class Reject extends TwiML { public enum Reason { REJECTED("rejected"), @@ -77,11 +82,26 @@ public Reject.Reason getReason() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Reject.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private Reject.Reason reason; /** * Rejection reason */ + @JacksonXmlProperty(isAttribute = true, localName = "reason") public Builder reason(Reject.Reason reason) { this.reason = reason; return this; diff --git a/src/main/java/com/twilio/twiml/voice/Room.java b/src/main/java/com/twilio/twiml/voice/Room.java index e640382709..66ab6fa8c4 100644 --- a/src/main/java/com/twilio/twiml/voice/Room.java +++ b/src/main/java/com/twilio/twiml/voice/Room.java @@ -7,7 +7,11 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.util.HashMap; import java.util.Map; @@ -15,6 +19,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Room.Builder.class) public class Room extends TwiML { private final String participantIdentity; private final String name; @@ -82,6 +87,20 @@ public String getName() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Room.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private String participantIdentity; private String name; @@ -92,9 +111,16 @@ public Builder(String name) { this.name = name; } + /** + * Create a {@code } (for XML deserialization) + */ + private Builder() { + } + /** * Participant identity when connecting to the Room */ + @JacksonXmlProperty(isAttribute = true, localName = "participantIdentity") public Builder participantIdentity(String participantIdentity) { this.participantIdentity = participantIdentity; return this; diff --git a/src/main/java/com/twilio/twiml/voice/Say.java b/src/main/java/com/twilio/twiml/voice/Say.java index fa4be4c55d..8188d1ebf1 100644 --- a/src/main/java/com/twilio/twiml/voice/Say.java +++ b/src/main/java/com/twilio/twiml/voice/Say.java @@ -7,7 +7,11 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.util.HashMap; import java.util.Map; @@ -15,6 +19,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Say.Builder.class) public class Say extends TwiML { public enum Voice { MAN("man"), @@ -248,6 +253,20 @@ public String getMessage() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Say.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private Say.Voice voice; private Integer loop; private Say.Language language; @@ -269,6 +288,7 @@ public Builder() { /** * Voice to use */ + @JacksonXmlProperty(isAttribute = true, localName = "voice") public Builder voice(Say.Voice voice) { this.voice = voice; return this; @@ -277,6 +297,7 @@ public Builder voice(Say.Voice voice) { /** * Times to loop message */ + @JacksonXmlProperty(isAttribute = true, localName = "loop") public Builder loop(Integer loop) { this.loop = loop; return this; @@ -285,6 +306,7 @@ public Builder loop(Integer loop) { /** * Message langauge */ + @JacksonXmlProperty(isAttribute = true, localName = "language") public Builder language(Say.Language language) { this.language = language; return this; @@ -293,6 +315,7 @@ public Builder language(Say.Language language) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "break") public Builder break_(SsmlBreak ssmlBreak) { this.children.add(ssmlBreak); return this; @@ -301,6 +324,7 @@ public Builder break_(SsmlBreak ssmlBreak) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "emphasis") public Builder emphasis(SsmlEmphasis ssmlEmphasis) { this.children.add(ssmlEmphasis); return this; @@ -309,6 +333,7 @@ public Builder emphasis(SsmlEmphasis ssmlEmphasis) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "lang") public Builder lang(SsmlLang ssmlLang) { this.children.add(ssmlLang); return this; @@ -317,6 +342,7 @@ public Builder lang(SsmlLang ssmlLang) { /** * Add a child {@code

} element */ + @JacksonXmlProperty(isAttribute = false, localName = "p") public Builder p(SsmlP ssmlP) { this.children.add(ssmlP); return this; @@ -325,6 +351,7 @@ public Builder p(SsmlP ssmlP) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "phoneme") public Builder phoneme(SsmlPhoneme ssmlPhoneme) { this.children.add(ssmlPhoneme); return this; @@ -333,6 +360,7 @@ public Builder phoneme(SsmlPhoneme ssmlPhoneme) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "prosody") public Builder prosody(SsmlProsody ssmlProsody) { this.children.add(ssmlProsody); return this; @@ -341,6 +369,7 @@ public Builder prosody(SsmlProsody ssmlProsody) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "s") public Builder s(SsmlS ssmlS) { this.children.add(ssmlS); return this; @@ -349,6 +378,7 @@ public Builder s(SsmlS ssmlS) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "say-as") public Builder sayAs(SsmlSayAs ssmlSayAs) { this.children.add(ssmlSayAs); return this; @@ -357,6 +387,7 @@ public Builder sayAs(SsmlSayAs ssmlSayAs) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "sub") public Builder sub(SsmlSub ssmlSub) { this.children.add(ssmlSub); return this; @@ -365,6 +396,7 @@ public Builder sub(SsmlSub ssmlSub) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "w") public Builder w(SsmlW ssmlW) { this.children.add(ssmlW); return this; diff --git a/src/main/java/com/twilio/twiml/voice/Sim.java b/src/main/java/com/twilio/twiml/voice/Sim.java index dc23b01ac0..f2b68c83b5 100644 --- a/src/main/java/com/twilio/twiml/voice/Sim.java +++ b/src/main/java/com/twilio/twiml/voice/Sim.java @@ -7,11 +7,15 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Sim.Builder.class) public class Sim extends TwiML { private final String simSid; @@ -52,6 +56,20 @@ public String getSimSid() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Sim.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private String simSid; /** @@ -61,6 +79,12 @@ public Builder(String simSid) { this.simSid = simSid; } + /** + * Create a {@code } (for XML deserialization) + */ + private Builder() { + } + /** * Create and return resulting {@code } element */ diff --git a/src/main/java/com/twilio/twiml/voice/Sip.java b/src/main/java/com/twilio/twiml/voice/Sip.java index 166b048c69..17bd0e832d 100644 --- a/src/main/java/com/twilio/twiml/voice/Sip.java +++ b/src/main/java/com/twilio/twiml/voice/Sip.java @@ -7,9 +7,13 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.converter.Promoter; import com.twilio.http.HttpMethod; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.net.URI; import java.util.HashMap; @@ -20,6 +24,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Sip.Builder.class) public class Sip extends TwiML { public enum Event { INITIATED("initiated"), @@ -200,6 +205,20 @@ public URI getSipUrl() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Sip.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private String username; private String password; private URI url; @@ -223,9 +242,16 @@ public Builder(String sipUrl) { this.sipUrl = Promoter.uriFromString(sipUrl); } + /** + * Create a {@code } (for XML deserialization) + */ + private Builder() { + } + /** * SIP Username */ + @JacksonXmlProperty(isAttribute = true, localName = "username") public Builder username(String username) { this.username = username; return this; @@ -234,6 +260,7 @@ public Builder username(String username) { /** * SIP Password */ + @JacksonXmlProperty(isAttribute = true, localName = "password") public Builder password(String password) { this.password = password; return this; @@ -242,6 +269,7 @@ public Builder password(String password) { /** * Action URL */ + @JacksonXmlProperty(isAttribute = true, localName = "url") public Builder url(URI url) { this.url = url; return this; @@ -258,6 +286,7 @@ public Builder url(String url) { /** * Action URL method */ + @JacksonXmlProperty(isAttribute = true, localName = "method") public Builder method(HttpMethod method) { this.method = method; return this; @@ -266,6 +295,7 @@ public Builder method(HttpMethod method) { /** * Status callback events */ + @JacksonXmlProperty(isAttribute = true, localName = "statusCallbackEvent") public Builder statusCallbackEvents(List statusCallbackEvent) { this.statusCallbackEvent = statusCallbackEvent; return this; @@ -282,6 +312,7 @@ public Builder statusCallbackEvents(Sip.Event statusCallbackEvent) { /** * Status callback URL */ + @JacksonXmlProperty(isAttribute = true, localName = "statusCallback") public Builder statusCallback(URI statusCallback) { this.statusCallback = statusCallback; return this; @@ -298,6 +329,7 @@ public Builder statusCallback(String statusCallback) { /** * Status callback URL method */ + @JacksonXmlProperty(isAttribute = true, localName = "statusCallbackMethod") public Builder statusCallbackMethod(HttpMethod statusCallbackMethod) { this.statusCallbackMethod = statusCallbackMethod; return this; diff --git a/src/main/java/com/twilio/twiml/voice/Siprec.java b/src/main/java/com/twilio/twiml/voice/Siprec.java index 2a6cc28a03..6aee94af10 100644 --- a/src/main/java/com/twilio/twiml/voice/Siprec.java +++ b/src/main/java/com/twilio/twiml/voice/Siprec.java @@ -7,7 +7,11 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.util.HashMap; import java.util.Map; @@ -15,6 +19,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Siprec.Builder.class) public class Siprec extends TwiML { public enum Track { INBOUND_TRACK("inbound_track"), @@ -106,6 +111,20 @@ public Siprec.Track getTrack() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Siprec.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private String name; private String connectorName; private Siprec.Track track; @@ -113,6 +132,7 @@ public static class Builder extends TwiML.Builder { /** * Friendly name given to SIPREC */ + @JacksonXmlProperty(isAttribute = true, localName = "name") public Builder name(String name) { this.name = name; return this; @@ -121,6 +141,7 @@ public Builder name(String name) { /** * Unique name for Connector */ + @JacksonXmlProperty(isAttribute = true, localName = "connectorName") public Builder connectorName(String connectorName) { this.connectorName = connectorName; return this; @@ -129,6 +150,7 @@ public Builder connectorName(String connectorName) { /** * Track to be streamed to remote service */ + @JacksonXmlProperty(isAttribute = true, localName = "track") public Builder track(Siprec.Track track) { this.track = track; return this; @@ -137,6 +159,7 @@ public Builder track(Siprec.Track track) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Parameter") public Builder parameter(Parameter parameter) { this.children.add(parameter); return this; diff --git a/src/main/java/com/twilio/twiml/voice/Sms.java b/src/main/java/com/twilio/twiml/voice/Sms.java index 92395b0e1c..787f30f1b4 100644 --- a/src/main/java/com/twilio/twiml/voice/Sms.java +++ b/src/main/java/com/twilio/twiml/voice/Sms.java @@ -7,9 +7,13 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.converter.Promoter; import com.twilio.http.HttpMethod; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.net.URI; import java.util.HashMap; @@ -18,6 +22,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Sms.Builder.class) public class Sms extends TwiML { private final com.twilio.type.PhoneNumber to; private final com.twilio.type.PhoneNumber from; @@ -141,6 +146,20 @@ public String getMessage() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Sms.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private com.twilio.type.PhoneNumber to; private com.twilio.type.PhoneNumber from; private URI action; @@ -155,9 +174,16 @@ public Builder(String message) { this.message = message; } + /** + * Create a {@code } (for XML deserialization) + */ + private Builder() { + } + /** * Number to send message to */ + @JacksonXmlProperty(isAttribute = true, localName = "to") public Builder to(com.twilio.type.PhoneNumber to) { this.to = to; return this; @@ -174,6 +200,7 @@ public Builder to(String to) { /** * Number to send message from */ + @JacksonXmlProperty(isAttribute = true, localName = "from") public Builder from(com.twilio.type.PhoneNumber from) { this.from = from; return this; @@ -190,6 +217,7 @@ public Builder from(String from) { /** * Action URL */ + @JacksonXmlProperty(isAttribute = true, localName = "action") public Builder action(URI action) { this.action = action; return this; @@ -206,6 +234,7 @@ public Builder action(String action) { /** * Action URL method */ + @JacksonXmlProperty(isAttribute = true, localName = "method") public Builder method(HttpMethod method) { this.method = method; return this; @@ -214,6 +243,7 @@ public Builder method(HttpMethod method) { /** * Status callback URL */ + @JacksonXmlProperty(isAttribute = true, localName = "statusCallback") public Builder statusCallback(URI statusCallback) { this.statusCallback = statusCallback; return this; diff --git a/src/main/java/com/twilio/twiml/voice/SsmlBreak.java b/src/main/java/com/twilio/twiml/voice/SsmlBreak.java index 5545bcdf8a..7932ddd59e 100644 --- a/src/main/java/com/twilio/twiml/voice/SsmlBreak.java +++ b/src/main/java/com/twilio/twiml/voice/SsmlBreak.java @@ -7,7 +7,11 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.util.HashMap; import java.util.Map; @@ -15,6 +19,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = SsmlBreak.Builder.class) public class SsmlBreak extends TwiML { public enum Strength { NONE("none"), @@ -97,12 +102,27 @@ public String getTime() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a SsmlBreak.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private SsmlBreak.Strength strength; private String time; /** * Set a pause based on strength */ + @JacksonXmlProperty(isAttribute = true, localName = "strength") public Builder strength(SsmlBreak.Strength strength) { this.strength = strength; return this; @@ -112,6 +132,7 @@ public Builder strength(SsmlBreak.Strength strength) { * Set a pause to a specific length of time in seconds or milliseconds, * available values: [number]s, [number]ms */ + @JacksonXmlProperty(isAttribute = true, localName = "time") public Builder time(String time) { this.time = time; return this; diff --git a/src/main/java/com/twilio/twiml/voice/SsmlEmphasis.java b/src/main/java/com/twilio/twiml/voice/SsmlEmphasis.java index 29b951311a..cadd1f6837 100644 --- a/src/main/java/com/twilio/twiml/voice/SsmlEmphasis.java +++ b/src/main/java/com/twilio/twiml/voice/SsmlEmphasis.java @@ -7,7 +7,11 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.util.HashMap; import java.util.Map; @@ -15,6 +19,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = SsmlEmphasis.Builder.class) public class SsmlEmphasis extends TwiML { public enum Level { STRONG("strong"), @@ -98,6 +103,20 @@ public String getWords() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a SsmlEmphasis.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private SsmlEmphasis.Level level; private String words; @@ -117,6 +136,7 @@ public Builder() { /** * Specify the degree of emphasis */ + @JacksonXmlProperty(isAttribute = true, localName = "level") public Builder level(SsmlEmphasis.Level level) { this.level = level; return this; @@ -125,6 +145,7 @@ public Builder level(SsmlEmphasis.Level level) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "break") public Builder break_(SsmlBreak ssmlBreak) { this.children.add(ssmlBreak); return this; @@ -133,6 +154,7 @@ public Builder break_(SsmlBreak ssmlBreak) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "emphasis") public Builder emphasis(SsmlEmphasis ssmlEmphasis) { this.children.add(ssmlEmphasis); return this; @@ -141,6 +163,7 @@ public Builder emphasis(SsmlEmphasis ssmlEmphasis) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "lang") public Builder lang(SsmlLang ssmlLang) { this.children.add(ssmlLang); return this; @@ -149,6 +172,7 @@ public Builder lang(SsmlLang ssmlLang) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "phoneme") public Builder phoneme(SsmlPhoneme ssmlPhoneme) { this.children.add(ssmlPhoneme); return this; @@ -157,6 +181,7 @@ public Builder phoneme(SsmlPhoneme ssmlPhoneme) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "prosody") public Builder prosody(SsmlProsody ssmlProsody) { this.children.add(ssmlProsody); return this; @@ -165,6 +190,7 @@ public Builder prosody(SsmlProsody ssmlProsody) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "say-as") public Builder sayAs(SsmlSayAs ssmlSayAs) { this.children.add(ssmlSayAs); return this; @@ -173,6 +199,7 @@ public Builder sayAs(SsmlSayAs ssmlSayAs) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "sub") public Builder sub(SsmlSub ssmlSub) { this.children.add(ssmlSub); return this; @@ -181,6 +208,7 @@ public Builder sub(SsmlSub ssmlSub) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "w") public Builder w(SsmlW ssmlW) { this.children.add(ssmlW); return this; diff --git a/src/main/java/com/twilio/twiml/voice/SsmlLang.java b/src/main/java/com/twilio/twiml/voice/SsmlLang.java index 1ad9335f6b..94328090dd 100644 --- a/src/main/java/com/twilio/twiml/voice/SsmlLang.java +++ b/src/main/java/com/twilio/twiml/voice/SsmlLang.java @@ -7,7 +7,11 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.util.HashMap; import java.util.Map; @@ -15,6 +19,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = SsmlLang.Builder.class) public class SsmlLang extends TwiML { public enum XmlLang { DA_DK("da-DK"), @@ -120,6 +125,20 @@ public String getWords() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a SsmlLang.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private SsmlLang.XmlLang xmlLang; private String words; @@ -139,6 +158,7 @@ public Builder() { /** * Specify the language */ + @JacksonXmlProperty(isAttribute = true, localName = "xml:lang") public Builder xmlLang(SsmlLang.XmlLang xmlLang) { this.xmlLang = xmlLang; return this; @@ -147,6 +167,7 @@ public Builder xmlLang(SsmlLang.XmlLang xmlLang) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "break") public Builder break_(SsmlBreak ssmlBreak) { this.children.add(ssmlBreak); return this; @@ -155,6 +176,7 @@ public Builder break_(SsmlBreak ssmlBreak) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "emphasis") public Builder emphasis(SsmlEmphasis ssmlEmphasis) { this.children.add(ssmlEmphasis); return this; @@ -163,6 +185,7 @@ public Builder emphasis(SsmlEmphasis ssmlEmphasis) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "lang") public Builder lang(SsmlLang ssmlLang) { this.children.add(ssmlLang); return this; @@ -171,6 +194,7 @@ public Builder lang(SsmlLang ssmlLang) { /** * Add a child {@code

} element */ + @JacksonXmlProperty(isAttribute = false, localName = "p") public Builder p(SsmlP ssmlP) { this.children.add(ssmlP); return this; @@ -179,6 +203,7 @@ public Builder p(SsmlP ssmlP) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "phoneme") public Builder phoneme(SsmlPhoneme ssmlPhoneme) { this.children.add(ssmlPhoneme); return this; @@ -187,6 +212,7 @@ public Builder phoneme(SsmlPhoneme ssmlPhoneme) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "prosody") public Builder prosody(SsmlProsody ssmlProsody) { this.children.add(ssmlProsody); return this; @@ -195,6 +221,7 @@ public Builder prosody(SsmlProsody ssmlProsody) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "s") public Builder s(SsmlS ssmlS) { this.children.add(ssmlS); return this; @@ -203,6 +230,7 @@ public Builder s(SsmlS ssmlS) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "say-as") public Builder sayAs(SsmlSayAs ssmlSayAs) { this.children.add(ssmlSayAs); return this; @@ -211,6 +239,7 @@ public Builder sayAs(SsmlSayAs ssmlSayAs) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "sub") public Builder sub(SsmlSub ssmlSub) { this.children.add(ssmlSub); return this; @@ -219,6 +248,7 @@ public Builder sub(SsmlSub ssmlSub) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "w") public Builder w(SsmlW ssmlW) { this.children.add(ssmlW); return this; diff --git a/src/main/java/com/twilio/twiml/voice/SsmlP.java b/src/main/java/com/twilio/twiml/voice/SsmlP.java index 6ad0d00a11..190b4991ee 100644 --- a/src/main/java/com/twilio/twiml/voice/SsmlP.java +++ b/src/main/java/com/twilio/twiml/voice/SsmlP.java @@ -7,11 +7,16 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; /** * TwiML wrapper for {@code

} */ +@JsonDeserialize(builder = SsmlP.Builder.class) public class SsmlP extends TwiML { private final String words; @@ -52,6 +57,20 @@ public String getWords() { * Create a new {@code

} element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a SsmlP.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private String words; /** @@ -70,6 +89,7 @@ public Builder() { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "break") public Builder break_(SsmlBreak ssmlBreak) { this.children.add(ssmlBreak); return this; @@ -78,6 +98,7 @@ public Builder break_(SsmlBreak ssmlBreak) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "emphasis") public Builder emphasis(SsmlEmphasis ssmlEmphasis) { this.children.add(ssmlEmphasis); return this; @@ -86,6 +107,7 @@ public Builder emphasis(SsmlEmphasis ssmlEmphasis) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "lang") public Builder lang(SsmlLang ssmlLang) { this.children.add(ssmlLang); return this; @@ -94,6 +116,7 @@ public Builder lang(SsmlLang ssmlLang) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "phoneme") public Builder phoneme(SsmlPhoneme ssmlPhoneme) { this.children.add(ssmlPhoneme); return this; @@ -102,6 +125,7 @@ public Builder phoneme(SsmlPhoneme ssmlPhoneme) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "prosody") public Builder prosody(SsmlProsody ssmlProsody) { this.children.add(ssmlProsody); return this; @@ -110,6 +134,7 @@ public Builder prosody(SsmlProsody ssmlProsody) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "s") public Builder s(SsmlS ssmlS) { this.children.add(ssmlS); return this; @@ -118,6 +143,7 @@ public Builder s(SsmlS ssmlS) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "say-as") public Builder sayAs(SsmlSayAs ssmlSayAs) { this.children.add(ssmlSayAs); return this; @@ -126,6 +152,7 @@ public Builder sayAs(SsmlSayAs ssmlSayAs) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "sub") public Builder sub(SsmlSub ssmlSub) { this.children.add(ssmlSub); return this; @@ -134,6 +161,7 @@ public Builder sub(SsmlSub ssmlSub) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "w") public Builder w(SsmlW ssmlW) { this.children.add(ssmlW); return this; diff --git a/src/main/java/com/twilio/twiml/voice/SsmlPhoneme.java b/src/main/java/com/twilio/twiml/voice/SsmlPhoneme.java index 3eb9c818cb..6d67d67f1e 100644 --- a/src/main/java/com/twilio/twiml/voice/SsmlPhoneme.java +++ b/src/main/java/com/twilio/twiml/voice/SsmlPhoneme.java @@ -7,7 +7,11 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.util.HashMap; import java.util.Map; @@ -15,6 +19,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = SsmlPhoneme.Builder.class) public class SsmlPhoneme extends TwiML { public enum Alphabet { IPA("ipa"), @@ -111,6 +116,20 @@ public String getWords() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a SsmlPhoneme.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private SsmlPhoneme.Alphabet alphabet; private String ph; private String words; @@ -122,9 +141,16 @@ public Builder(String words) { this.words = words; } + /** + * Create a {@code } (for XML deserialization) + */ + private Builder() { + } + /** * Specify the phonetic alphabet */ + @JacksonXmlProperty(isAttribute = true, localName = "alphabet") public Builder alphabet(SsmlPhoneme.Alphabet alphabet) { this.alphabet = alphabet; return this; @@ -133,6 +159,7 @@ public Builder alphabet(SsmlPhoneme.Alphabet alphabet) { /** * Specifiy the phonetic symbols for pronunciation */ + @JacksonXmlProperty(isAttribute = true, localName = "ph") public Builder ph(String ph) { this.ph = ph; return this; diff --git a/src/main/java/com/twilio/twiml/voice/SsmlProsody.java b/src/main/java/com/twilio/twiml/voice/SsmlProsody.java index 8a8e7f4e4b..e5175af2e7 100644 --- a/src/main/java/com/twilio/twiml/voice/SsmlProsody.java +++ b/src/main/java/com/twilio/twiml/voice/SsmlProsody.java @@ -7,7 +7,11 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.util.HashMap; import java.util.Map; @@ -15,6 +19,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = SsmlProsody.Builder.class) public class SsmlProsody extends TwiML { private final String volume; private final String rate; @@ -115,6 +120,20 @@ public String getWords() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a SsmlProsody.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private String volume; private String rate; private String pitch; @@ -137,6 +156,7 @@ public Builder() { * Specify the volume, available values: default, silent, x-soft, soft, medium, * loud, x-loud, +ndB, -ndB */ + @JacksonXmlProperty(isAttribute = true, localName = "volume") public Builder volume(String volume) { this.volume = volume; return this; @@ -145,6 +165,7 @@ public Builder volume(String volume) { /** * Specify the rate, available values: x-slow, slow, medium, fast, x-fast, n% */ + @JacksonXmlProperty(isAttribute = true, localName = "rate") public Builder rate(String rate) { this.rate = rate; return this; @@ -154,6 +175,7 @@ public Builder rate(String rate) { * Specify the pitch, available values: default, x-low, low, medium, high, * x-high, +n%, -n% */ + @JacksonXmlProperty(isAttribute = true, localName = "pitch") public Builder pitch(String pitch) { this.pitch = pitch; return this; @@ -162,6 +184,7 @@ public Builder pitch(String pitch) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "break") public Builder break_(SsmlBreak ssmlBreak) { this.children.add(ssmlBreak); return this; @@ -170,6 +193,7 @@ public Builder break_(SsmlBreak ssmlBreak) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "emphasis") public Builder emphasis(SsmlEmphasis ssmlEmphasis) { this.children.add(ssmlEmphasis); return this; @@ -178,6 +202,7 @@ public Builder emphasis(SsmlEmphasis ssmlEmphasis) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "lang") public Builder lang(SsmlLang ssmlLang) { this.children.add(ssmlLang); return this; @@ -186,6 +211,7 @@ public Builder lang(SsmlLang ssmlLang) { /** * Add a child {@code

} element */ + @JacksonXmlProperty(isAttribute = false, localName = "p") public Builder p(SsmlP ssmlP) { this.children.add(ssmlP); return this; @@ -194,6 +220,7 @@ public Builder p(SsmlP ssmlP) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "phoneme") public Builder phoneme(SsmlPhoneme ssmlPhoneme) { this.children.add(ssmlPhoneme); return this; @@ -202,6 +229,7 @@ public Builder phoneme(SsmlPhoneme ssmlPhoneme) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "prosody") public Builder prosody(SsmlProsody ssmlProsody) { this.children.add(ssmlProsody); return this; @@ -210,6 +238,7 @@ public Builder prosody(SsmlProsody ssmlProsody) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "s") public Builder s(SsmlS ssmlS) { this.children.add(ssmlS); return this; @@ -218,6 +247,7 @@ public Builder s(SsmlS ssmlS) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "say-as") public Builder sayAs(SsmlSayAs ssmlSayAs) { this.children.add(ssmlSayAs); return this; @@ -226,6 +256,7 @@ public Builder sayAs(SsmlSayAs ssmlSayAs) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "sub") public Builder sub(SsmlSub ssmlSub) { this.children.add(ssmlSub); return this; @@ -234,6 +265,7 @@ public Builder sub(SsmlSub ssmlSub) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "w") public Builder w(SsmlW ssmlW) { this.children.add(ssmlW); return this; diff --git a/src/main/java/com/twilio/twiml/voice/SsmlS.java b/src/main/java/com/twilio/twiml/voice/SsmlS.java index 8209048aed..9ac5236e7c 100644 --- a/src/main/java/com/twilio/twiml/voice/SsmlS.java +++ b/src/main/java/com/twilio/twiml/voice/SsmlS.java @@ -7,11 +7,16 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = SsmlS.Builder.class) public class SsmlS extends TwiML { private final String words; @@ -52,6 +57,20 @@ public String getWords() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a SsmlS.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private String words; /** @@ -70,6 +89,7 @@ public Builder() { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "break") public Builder break_(SsmlBreak ssmlBreak) { this.children.add(ssmlBreak); return this; @@ -78,6 +98,7 @@ public Builder break_(SsmlBreak ssmlBreak) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "emphasis") public Builder emphasis(SsmlEmphasis ssmlEmphasis) { this.children.add(ssmlEmphasis); return this; @@ -86,6 +107,7 @@ public Builder emphasis(SsmlEmphasis ssmlEmphasis) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "lang") public Builder lang(SsmlLang ssmlLang) { this.children.add(ssmlLang); return this; @@ -94,6 +116,7 @@ public Builder lang(SsmlLang ssmlLang) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "phoneme") public Builder phoneme(SsmlPhoneme ssmlPhoneme) { this.children.add(ssmlPhoneme); return this; @@ -102,6 +125,7 @@ public Builder phoneme(SsmlPhoneme ssmlPhoneme) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "prosody") public Builder prosody(SsmlProsody ssmlProsody) { this.children.add(ssmlProsody); return this; @@ -110,6 +134,7 @@ public Builder prosody(SsmlProsody ssmlProsody) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "say-as") public Builder sayAs(SsmlSayAs ssmlSayAs) { this.children.add(ssmlSayAs); return this; @@ -118,6 +143,7 @@ public Builder sayAs(SsmlSayAs ssmlSayAs) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "sub") public Builder sub(SsmlSub ssmlSub) { this.children.add(ssmlSub); return this; @@ -126,6 +152,7 @@ public Builder sub(SsmlSub ssmlSub) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "w") public Builder w(SsmlW ssmlW) { this.children.add(ssmlW); return this; diff --git a/src/main/java/com/twilio/twiml/voice/SsmlSayAs.java b/src/main/java/com/twilio/twiml/voice/SsmlSayAs.java index d3fd6c86b3..8e63aaca48 100644 --- a/src/main/java/com/twilio/twiml/voice/SsmlSayAs.java +++ b/src/main/java/com/twilio/twiml/voice/SsmlSayAs.java @@ -7,7 +7,11 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.util.HashMap; import java.util.Map; @@ -15,6 +19,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = SsmlSayAs.Builder.class) public class SsmlSayAs extends TwiML { public enum InterpretAs { CHARACTER("character"), @@ -146,6 +151,20 @@ public String getWords() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a SsmlSayAs.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private SsmlSayAs.InterpretAs interpretAs; private SsmlSayAs.Role role; private String words; @@ -157,9 +176,16 @@ public Builder(String words) { this.words = words; } + /** + * Create a {@code } (for XML deserialization) + */ + private Builder() { + } + /** * Specify the type of words are spoken */ + @JacksonXmlProperty(isAttribute = true, localName = "interpret-as") public Builder interpretAs(SsmlSayAs.InterpretAs interpretAs) { this.interpretAs = interpretAs; return this; @@ -168,6 +194,7 @@ public Builder interpretAs(SsmlSayAs.InterpretAs interpretAs) { /** * Specify the format of the date when interpret-as is set to date */ + @JacksonXmlProperty(isAttribute = true, localName = "role") public Builder role(SsmlSayAs.Role role) { this.role = role; return this; diff --git a/src/main/java/com/twilio/twiml/voice/SsmlSub.java b/src/main/java/com/twilio/twiml/voice/SsmlSub.java index 521036b246..a17d4ac993 100644 --- a/src/main/java/com/twilio/twiml/voice/SsmlSub.java +++ b/src/main/java/com/twilio/twiml/voice/SsmlSub.java @@ -7,7 +7,11 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.util.HashMap; import java.util.Map; @@ -15,6 +19,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = SsmlSub.Builder.class) public class SsmlSub extends TwiML { private final String alias; private final String words; @@ -84,6 +89,20 @@ public String getWords() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a SsmlSub.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private String alias; private String words; @@ -94,10 +113,17 @@ public Builder(String words) { this.words = words; } + /** + * Create a {@code } (for XML deserialization) + */ + private Builder() { + } + /** * Substitute a different word (or pronunciation) for selected text such as an * acronym or abbreviation */ + @JacksonXmlProperty(isAttribute = true, localName = "alias") public Builder alias(String alias) { this.alias = alias; return this; diff --git a/src/main/java/com/twilio/twiml/voice/SsmlW.java b/src/main/java/com/twilio/twiml/voice/SsmlW.java index 2e544f7d1e..d6f20bae6d 100644 --- a/src/main/java/com/twilio/twiml/voice/SsmlW.java +++ b/src/main/java/com/twilio/twiml/voice/SsmlW.java @@ -7,7 +7,11 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.util.HashMap; import java.util.Map; @@ -15,6 +19,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = SsmlW.Builder.class) public class SsmlW extends TwiML { private final String role; private final String words; @@ -84,6 +89,20 @@ public String getWords() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a SsmlW.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private String role; private String words; @@ -104,6 +123,7 @@ public Builder() { * Customize the pronunciation of words by specifying the word’s part of speech * or alternate meaning */ + @JacksonXmlProperty(isAttribute = true, localName = "role") public Builder role(String role) { this.role = role; return this; @@ -112,6 +132,7 @@ public Builder role(String role) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "break") public Builder break_(SsmlBreak ssmlBreak) { this.children.add(ssmlBreak); return this; @@ -120,6 +141,7 @@ public Builder break_(SsmlBreak ssmlBreak) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "emphasis") public Builder emphasis(SsmlEmphasis ssmlEmphasis) { this.children.add(ssmlEmphasis); return this; @@ -128,6 +150,7 @@ public Builder emphasis(SsmlEmphasis ssmlEmphasis) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "phoneme") public Builder phoneme(SsmlPhoneme ssmlPhoneme) { this.children.add(ssmlPhoneme); return this; @@ -136,6 +159,7 @@ public Builder phoneme(SsmlPhoneme ssmlPhoneme) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "prosody") public Builder prosody(SsmlProsody ssmlProsody) { this.children.add(ssmlProsody); return this; @@ -144,6 +168,7 @@ public Builder prosody(SsmlProsody ssmlProsody) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "say-as") public Builder sayAs(SsmlSayAs ssmlSayAs) { this.children.add(ssmlSayAs); return this; @@ -152,6 +177,7 @@ public Builder sayAs(SsmlSayAs ssmlSayAs) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "sub") public Builder sub(SsmlSub ssmlSub) { this.children.add(ssmlSub); return this; diff --git a/src/main/java/com/twilio/twiml/voice/Start.java b/src/main/java/com/twilio/twiml/voice/Start.java index 2f88dd1ecc..2d97c357b7 100644 --- a/src/main/java/com/twilio/twiml/voice/Start.java +++ b/src/main/java/com/twilio/twiml/voice/Start.java @@ -7,9 +7,13 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.converter.Promoter; import com.twilio.http.HttpMethod; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.net.URI; import java.util.HashMap; @@ -18,6 +22,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Start.Builder.class) public class Start extends TwiML { private final URI action; private final HttpMethod method; @@ -79,12 +84,27 @@ public HttpMethod getMethod() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Start.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private URI action; private HttpMethod method; /** * Action URL */ + @JacksonXmlProperty(isAttribute = true, localName = "action") public Builder action(URI action) { this.action = action; return this; @@ -101,6 +121,7 @@ public Builder action(String action) { /** * Action URL method */ + @JacksonXmlProperty(isAttribute = true, localName = "method") public Builder method(HttpMethod method) { this.method = method; return this; @@ -109,6 +130,7 @@ public Builder method(HttpMethod method) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Stream") public Builder stream(Stream stream) { this.children.add(stream); return this; @@ -117,6 +139,7 @@ public Builder stream(Stream stream) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Siprec") public Builder siprec(Siprec siprec) { this.children.add(siprec); return this; diff --git a/src/main/java/com/twilio/twiml/voice/Stop.java b/src/main/java/com/twilio/twiml/voice/Stop.java index 02dd02e1b5..844cd9412e 100644 --- a/src/main/java/com/twilio/twiml/voice/Stop.java +++ b/src/main/java/com/twilio/twiml/voice/Stop.java @@ -7,11 +7,16 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Stop.Builder.class) public class Stop extends TwiML { /** * For XML Serialization/Deserialization @@ -31,9 +36,24 @@ private Stop(Builder b) { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Stop.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Stream") public Builder stream(Stream stream) { this.children.add(stream); return this; @@ -42,6 +62,7 @@ public Builder stream(Stream stream) { /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Siprec") public Builder siprec(Siprec siprec) { this.children.add(siprec); return this; diff --git a/src/main/java/com/twilio/twiml/voice/Stream.java b/src/main/java/com/twilio/twiml/voice/Stream.java index 24d90a3014..b0a0ef4705 100644 --- a/src/main/java/com/twilio/twiml/voice/Stream.java +++ b/src/main/java/com/twilio/twiml/voice/Stream.java @@ -7,7 +7,11 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.util.HashMap; import java.util.Map; @@ -15,6 +19,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Stream.Builder.class) public class Stream extends TwiML { public enum Track { INBOUND_TRACK("inbound_track"), @@ -163,6 +168,20 @@ public Stream.StatusCallbackMethod getStatusCallbackMethod() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Stream.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private String name; private String connectorName; private String url; @@ -173,6 +192,7 @@ public static class Builder extends TwiML.Builder { /** * Friendly name given to the Stream */ + @JacksonXmlProperty(isAttribute = true, localName = "name") public Builder name(String name) { this.name = name; return this; @@ -181,6 +201,7 @@ public Builder name(String name) { /** * Unique name for Stream Connector */ + @JacksonXmlProperty(isAttribute = true, localName = "connectorName") public Builder connectorName(String connectorName) { this.connectorName = connectorName; return this; @@ -189,6 +210,7 @@ public Builder connectorName(String connectorName) { /** * URL of the remote service where the Stream is routed */ + @JacksonXmlProperty(isAttribute = true, localName = "url") public Builder url(String url) { this.url = url; return this; @@ -197,6 +219,7 @@ public Builder url(String url) { /** * Track to be streamed to remote service */ + @JacksonXmlProperty(isAttribute = true, localName = "track") public Builder track(Stream.Track track) { this.track = track; return this; @@ -205,6 +228,7 @@ public Builder track(Stream.Track track) { /** * Status Callback URL */ + @JacksonXmlProperty(isAttribute = true, localName = "statusCallback") public Builder statusCallback(String statusCallback) { this.statusCallback = statusCallback; return this; @@ -213,6 +237,7 @@ public Builder statusCallback(String statusCallback) { /** * Status Callback URL method */ + @JacksonXmlProperty(isAttribute = true, localName = "statusCallbackMethod") public Builder statusCallbackMethod(Stream.StatusCallbackMethod statusCallbackMethod) { this.statusCallbackMethod = statusCallbackMethod; return this; @@ -221,6 +246,7 @@ public Builder statusCallbackMethod(Stream.StatusCallbackMethod statusCallbackMe /** * Add a child {@code } element */ + @JacksonXmlProperty(isAttribute = false, localName = "Parameter") public Builder parameter(Parameter parameter) { this.children.add(parameter); return this; diff --git a/src/main/java/com/twilio/twiml/voice/Task.java b/src/main/java/com/twilio/twiml/voice/Task.java index 5e323e7896..f2b4de1dca 100644 --- a/src/main/java/com/twilio/twiml/voice/Task.java +++ b/src/main/java/com/twilio/twiml/voice/Task.java @@ -7,7 +7,11 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.util.HashMap; import java.util.Map; @@ -15,6 +19,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = Task.Builder.class) public class Task extends TwiML { private final Integer priority; private final Integer timeout; @@ -96,6 +101,20 @@ public String getBody() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a Task.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private Integer priority; private Integer timeout; private String body; @@ -107,9 +126,16 @@ public Builder(String body) { this.body = body; } + /** + * Create a {@code } (for XML deserialization) + */ + private Builder() { + } + /** * Task priority */ + @JacksonXmlProperty(isAttribute = true, localName = "priority") public Builder priority(Integer priority) { this.priority = priority; return this; @@ -118,6 +144,7 @@ public Builder priority(Integer priority) { /** * Timeout associated with task */ + @JacksonXmlProperty(isAttribute = true, localName = "timeout") public Builder timeout(Integer timeout) { this.timeout = timeout; return this; diff --git a/src/main/java/com/twilio/twiml/voice/VirtualAgent.java b/src/main/java/com/twilio/twiml/voice/VirtualAgent.java index 32dde10d7e..c8ee5b8d5e 100644 --- a/src/main/java/com/twilio/twiml/voice/VirtualAgent.java +++ b/src/main/java/com/twilio/twiml/voice/VirtualAgent.java @@ -7,7 +7,11 @@ package com.twilio.twiml.voice; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.twilio.twiml.TwiML; +import com.twilio.twiml.TwiMLException; import java.util.HashMap; import java.util.Map; @@ -15,6 +19,7 @@ /** * TwiML wrapper for {@code } */ +@JsonDeserialize(builder = VirtualAgent.Builder.class) public class VirtualAgent extends TwiML { private final String connectorName; private final String language; @@ -104,6 +109,20 @@ public String getStatusCallback() { * Create a new {@code } element */ public static class Builder extends TwiML.Builder { + /** + * Create and return a {@code } from an XML string + */ + public static Builder fromXml(final String xml) throws TwiMLException { + try { + return OBJECT_MAPPER.readValue(xml, Builder.class); + } catch (final JsonProcessingException jpe) { + throw new TwiMLException( + "Failed to deserialize a VirtualAgent.Builder from the provided XML string: " + jpe.getMessage()); + } catch (final Exception e) { + throw new TwiMLException("Unhandled exception: " + e.getMessage()); + } + } + private String connectorName; private String language; private Boolean sentimentAnalysis; @@ -112,6 +131,7 @@ public static class Builder extends TwiML.Builder { /** * Defines the conversation profile Dialogflow needs to use */ + @JacksonXmlProperty(isAttribute = true, localName = "connectorName") public Builder connectorName(String connectorName) { this.connectorName = connectorName; return this; @@ -120,6 +140,7 @@ public Builder connectorName(String connectorName) { /** * Language to be used by Dialogflow to transcribe speech */ + @JacksonXmlProperty(isAttribute = true, localName = "language") public Builder language(String language) { this.language = language; return this; @@ -128,6 +149,7 @@ public Builder language(String language) { /** * Whether sentiment analysis needs to be enabled or not */ + @JacksonXmlProperty(isAttribute = true, localName = "sentimentAnalysis") public Builder sentimentAnalysis(Boolean sentimentAnalysis) { this.sentimentAnalysis = sentimentAnalysis; return this; @@ -136,6 +158,7 @@ public Builder sentimentAnalysis(Boolean sentimentAnalysis) { /** * URL to post status callbacks from Twilio */ + @JacksonXmlProperty(isAttribute = true, localName = "statusCallback") public Builder statusCallback(String statusCallback) { this.statusCallback = statusCallback; return this; diff --git a/src/test/java/com/twilio/twiml/FaxResponseTest.java b/src/test/java/com/twilio/twiml/FaxResponseTest.java index 547b4bc353..ba592258ca 100644 --- a/src/test/java/com/twilio/twiml/FaxResponseTest.java +++ b/src/test/java/com/twilio/twiml/FaxResponseTest.java @@ -147,4 +147,36 @@ public void testElementWithGenericNodeAttributes() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final FaxResponse elem = new FaxResponse.Builder().build(); + + Assert.assertEquals( + FaxResponse.Builder.fromXml("").build().toXml(), + elem.toXml() + ); + } + + @Test + public void testXmlChildrenDeserialization() { + final FaxResponse.Builder builder = new FaxResponse.Builder(); + + builder.receive(new Receive.Builder() + .action(URI.create("https://example.com")) + .method(HttpMethod.GET) + .mediaType(Receive.MediaType.APPLICATION_PDF) + .pageSize(Receive.PageSize.LETTER) + .storeMedia(true) + .build()); + + final FaxResponse elem = builder.build(); + + Assert.assertEquals( + FaxResponse.Builder.fromXml("" + + "" + + "").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/MessagingResponseTest.java b/src/test/java/com/twilio/twiml/MessagingResponseTest.java index 6ee2ef5920..61b8210e85 100644 --- a/src/test/java/com/twilio/twiml/MessagingResponseTest.java +++ b/src/test/java/com/twilio/twiml/MessagingResponseTest.java @@ -151,4 +151,39 @@ public void testElementWithGenericNodeAttributes() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final MessagingResponse elem = new MessagingResponse.Builder().build(); + + Assert.assertEquals( + MessagingResponse.Builder.fromXml("").build().toXml(), + elem.toXml() + ); + } + + @Test + public void testXmlChildrenDeserialization() { + final MessagingResponse.Builder builder = new MessagingResponse.Builder(); + + builder.message(new Message.Builder("body") + .to("to") + .from("from") + .action(URI.create("https://example.com")) + .method(HttpMethod.GET) + .statusCallback(URI.create("https://example.com")) + .build()); + + builder.redirect(new Redirect.Builder(URI.create("https://example.com")).method(HttpMethod.GET).build()); + + final MessagingResponse elem = builder.build(); + + Assert.assertEquals( + MessagingResponse.Builder.fromXml("" + + "body" + + "https://example.com" + + "").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/VoiceResponseTest.java b/src/test/java/com/twilio/twiml/VoiceResponseTest.java index 88c1b93c48..38863d5ce1 100644 --- a/src/test/java/com/twilio/twiml/VoiceResponseTest.java +++ b/src/test/java/com/twilio/twiml/VoiceResponseTest.java @@ -310,4 +310,178 @@ public void testElementWithGenericNodeAttributes() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final VoiceResponse elem = new VoiceResponse.Builder().build(); + + Assert.assertEquals( + VoiceResponse.Builder.fromXml("").build().toXml(), + elem.toXml() + ); + } + + @Test + public void testXmlChildrenDeserialization() { + final VoiceResponse.Builder builder = new VoiceResponse.Builder(); + + builder.connect(new Connect.Builder().action(URI.create("https://example.com")).method(HttpMethod.GET).build()); + + builder.dial(new Dial.Builder("number") + .action(URI.create("https://example.com")) + .method(HttpMethod.GET) + .timeout(1) + .hangupOnStar(true) + .timeLimit(1) + .callerId("caller_id") + .record(Dial.Record.DO_NOT_RECORD) + .trim(Dial.Trim.TRIM_SILENCE) + .recordingStatusCallback(URI.create("https://example.com")) + .recordingStatusCallbackMethod(HttpMethod.GET) + .recordingStatusCallbackEvents(Promoter.listOfOne(Dial.RecordingEvent.IN_PROGRESS)) + .answerOnBridge(true) + .ringTone(Dial.RingTone.AT) + .recordingTrack(Dial.RecordingTrack.BOTH) + .sequential(true) + .referUrl(URI.create("https://example.com")) + .referMethod(HttpMethod.GET) + .build()); + + builder.echo(new Echo.Builder().build()); + + builder.enqueue(new Enqueue.Builder("name") + .action(URI.create("https://example.com")) + .method(HttpMethod.GET) + .waitUrl(URI.create("https://example.com")) + .waitUrlMethod(HttpMethod.GET) + .workflowSid("workflow_sid") + .build()); + + builder.gather(new Gather.Builder() + .inputs(Promoter.listOfOne(Gather.Input.DTMF)) + .action(URI.create("https://example.com")) + .method(HttpMethod.GET) + .timeout(1) + .speechTimeout("speech_timeout") + .maxSpeechTime(1) + .profanityFilter(true) + .finishOnKey("finish_on_key") + .numDigits(1) + .partialResultCallback(URI.create("https://example.com")) + .partialResultCallbackMethod(HttpMethod.GET) + .language(Gather.Language.AF_ZA) + .hints("hints") + .bargeIn(true) + .debug(true) + .actionOnEmptyResult(true) + .speechModel(Gather.SpeechModel.DEFAULT) + .enhanced(true) + .build()); + + builder.hangup(new Hangup.Builder().build()); + + builder.leave(new Leave.Builder().build()); + + builder.pause(new Pause.Builder().length(1).build()); + + builder.play(new Play.Builder(URI.create("https://example.com")).loop(1).digits("digits").build()); + + builder.queue(new Queue.Builder("name") + .url(URI.create("https://example.com")) + .method(HttpMethod.GET) + .reservationSid("reservation_sid") + .postWorkActivitySid("post_work_activity_sid") + .build()); + + builder.record(new Record.Builder() + .action(URI.create("https://example.com")) + .method(HttpMethod.GET) + .timeout(1) + .finishOnKey("finish_on_key") + .maxLength(1) + .playBeep(true) + .trim(Record.Trim.TRIM_SILENCE) + .recordingStatusCallback(URI.create("https://example.com")) + .recordingStatusCallbackMethod(HttpMethod.GET) + .recordingStatusCallbackEvents(Promoter.listOfOne(Record.RecordingEvent.IN_PROGRESS)) + .transcribe(true) + .transcribeCallback(URI.create("https://example.com")) + .build()); + + builder.redirect(new Redirect.Builder(URI.create("https://example.com")).method(HttpMethod.GET).build()); + + builder.reject(new Reject.Builder().reason(Reject.Reason.REJECTED).build()); + + builder.say(new Say.Builder("message").voice(Say.Voice.MAN).loop(1).language(Say.Language.ARB).build()); + + builder.sms(new Sms.Builder("message") + .to(new com.twilio.type.PhoneNumber("+15558675310")) + .from(new com.twilio.type.PhoneNumber("+15017122661")) + .action(URI.create("https://example.com")) + .method(HttpMethod.GET) + .statusCallback(URI.create("https://example.com")) + .build()); + + builder.pay(new Pay.Builder() + .input(Pay.Input.DTMF) + .action(URI.create("https://example.com")) + .bankAccountType(Pay.BankAccountType.CONSUMER_CHECKING) + .statusCallback(URI.create("https://example.com")) + .statusCallbackMethod(Pay.StatusCallbackMethod.GET) + .timeout(1) + .maxAttempts(1) + .securityCode(true) + .postalCode("postal_code") + .minPostalCodeLength(1) + .paymentConnector("payment_connector") + .paymentMethod(Pay.PaymentMethod.ACH_DEBIT) + .tokenType(Pay.TokenType.ONE_TIME) + .chargeAmount("charge_amount") + .currency("currency") + .description("description") + .validCardTypes(Promoter.listOfOne(Pay.ValidCardTypes.VISA)) + .language(Pay.Language.DE_DE) + .build()); + + builder.prompt(new Prompt.Builder() + .for_(Prompt.For.PAYMENT_CARD_NUMBER) + .errorTypes(Promoter.listOfOne(Prompt.ErrorType.TIMEOUT)) + .cardTypes(Promoter.listOfOne(Prompt.CardType.VISA)) + .attempts(Promoter.listOfOne(1)) + .build()); + + builder.start(new Start.Builder().action(URI.create("https://example.com")).method(HttpMethod.GET).build()); + + builder.stop(new Stop.Builder().build()); + + builder.refer(new Refer.Builder().action(URI.create("https://example.com")).method(HttpMethod.GET).build()); + + final VoiceResponse elem = builder.build(); + + Assert.assertEquals( + VoiceResponse.Builder.fromXml("" + + "" + + "number" + + "" + + "name" + + "" + + "" + + "" + + "" + + "https://example.com" + + "name" + + "" + + "https://example.com" + + "" + + "message" + + "message" + + "" + + "" + + "" + + "" + + "" + + "").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/fax/ReceiveTest.java b/src/test/java/com/twilio/twiml/fax/ReceiveTest.java index 6545e99bcc..6a94655b00 100644 --- a/src/test/java/com/twilio/twiml/fax/ReceiveTest.java +++ b/src/test/java/com/twilio/twiml/fax/ReceiveTest.java @@ -122,4 +122,20 @@ public void testElementWithGenericNode() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Receive elem = new Receive.Builder() + .action(URI.create("https://example.com")) + .method(HttpMethod.GET) + .mediaType(Receive.MediaType.APPLICATION_PDF) + .pageSize(Receive.PageSize.LETTER) + .storeMedia(true) + .build(); + + Assert.assertEquals( + Receive.Builder.fromXml("").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/messaging/BodyTest.java b/src/test/java/com/twilio/twiml/messaging/BodyTest.java index b1d8a9db4f..afc0267955 100644 --- a/src/test/java/com/twilio/twiml/messaging/BodyTest.java +++ b/src/test/java/com/twilio/twiml/messaging/BodyTest.java @@ -24,4 +24,14 @@ public void testElementWithParams() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Body elem = new Body.Builder("message").build(); + + Assert.assertEquals( + Body.Builder.fromXml("message").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/messaging/MediaTest.java b/src/test/java/com/twilio/twiml/messaging/MediaTest.java index e38cad2d28..ab6bfe0bd2 100644 --- a/src/test/java/com/twilio/twiml/messaging/MediaTest.java +++ b/src/test/java/com/twilio/twiml/messaging/MediaTest.java @@ -26,4 +26,14 @@ public void testElementWithParams() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Media elem = new Media.Builder(URI.create("https://example.com")).build(); + + Assert.assertEquals( + Media.Builder.fromXml("https://example.com").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/messaging/MessageTest.java b/src/test/java/com/twilio/twiml/messaging/MessageTest.java index de4da7dd80..a79a70b9dd 100644 --- a/src/test/java/com/twilio/twiml/messaging/MessageTest.java +++ b/src/test/java/com/twilio/twiml/messaging/MessageTest.java @@ -161,4 +161,39 @@ public void testElementWithGenericNodeAttributes() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Message elem = new Message.Builder("body") + .to("to") + .from("from") + .action(URI.create("https://example.com")) + .method(HttpMethod.GET) + .statusCallback(URI.create("https://example.com")) + .build(); + + Assert.assertEquals( + Message.Builder.fromXml("body").build().toXml(), + elem.toXml() + ); + } + + @Test + public void testXmlChildrenDeserialization() { + final Message.Builder builder = new Message.Builder(); + + builder.body(new Body.Builder("message").build()); + + builder.media(new Media.Builder(URI.create("https://example.com")).build()); + + final Message elem = builder.build(); + + Assert.assertEquals( + Message.Builder.fromXml("" + + "message" + + "https://example.com" + + "").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/messaging/RedirectTest.java b/src/test/java/com/twilio/twiml/messaging/RedirectTest.java index 34ff1f533a..cdf0530730 100644 --- a/src/test/java/com/twilio/twiml/messaging/RedirectTest.java +++ b/src/test/java/com/twilio/twiml/messaging/RedirectTest.java @@ -27,4 +27,14 @@ public void testElementWithParams() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Redirect elem = new Redirect.Builder(URI.create("https://example.com")).method(HttpMethod.GET).build(); + + Assert.assertEquals( + Redirect.Builder.fromXml("https://example.com").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/AutopilotTest.java b/src/test/java/com/twilio/twiml/voice/AutopilotTest.java index 8701f94776..8cb317ff6a 100644 --- a/src/test/java/com/twilio/twiml/voice/AutopilotTest.java +++ b/src/test/java/com/twilio/twiml/voice/AutopilotTest.java @@ -24,4 +24,14 @@ public void testElementWithParams() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Autopilot elem = new Autopilot.Builder("name").build(); + + Assert.assertEquals( + Autopilot.Builder.fromXml("name").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/ClientTest.java b/src/test/java/com/twilio/twiml/voice/ClientTest.java index e17b7320e4..30b5400e1b 100644 --- a/src/test/java/com/twilio/twiml/voice/ClientTest.java +++ b/src/test/java/com/twilio/twiml/voice/ClientTest.java @@ -163,4 +163,39 @@ public void testElementWithGenericNodeAttributes() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Client elem = new Client.Builder("identity") + .url(URI.create("https://example.com")) + .method(HttpMethod.GET) + .statusCallbackEvents(Promoter.listOfOne(Client.Event.INITIATED)) + .statusCallback(URI.create("https://example.com")) + .statusCallbackMethod(HttpMethod.GET) + .build(); + + Assert.assertEquals( + Client.Builder.fromXml("identity").build().toXml(), + elem.toXml() + ); + } + + @Test + public void testXmlChildrenDeserialization() { + final Client.Builder builder = new Client.Builder(); + + builder.identity(new Identity.Builder("client_identity").build()); + + builder.parameter(new Parameter.Builder().name("name").value("value").build()); + + final Client elem = builder.build(); + + Assert.assertEquals( + Client.Builder.fromXml("" + + "client_identity" + + "" + + "").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/ConferenceTest.java b/src/test/java/com/twilio/twiml/voice/ConferenceTest.java index 556256e412..15d68c07e8 100644 --- a/src/test/java/com/twilio/twiml/voice/ConferenceTest.java +++ b/src/test/java/com/twilio/twiml/voice/ConferenceTest.java @@ -50,4 +50,35 @@ public void testElementWithParams() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Conference elem = new Conference.Builder("name") + .muted(true) + .beep(Conference.Beep.TRUE) + .startConferenceOnEnter(true) + .endConferenceOnExit(true) + .waitUrl(URI.create("https://example.com")) + .waitMethod(HttpMethod.GET) + .maxParticipants(1) + .record(Conference.Record.DO_NOT_RECORD) + .region(Conference.Region.US1) + .coach("CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") + .trim(Conference.Trim.TRIM_SILENCE) + .statusCallbackEvents(Promoter.listOfOne(Conference.Event.START)) + .statusCallback(URI.create("https://example.com")) + .statusCallbackMethod(HttpMethod.GET) + .recordingStatusCallback(URI.create("https://example.com")) + .recordingStatusCallbackMethod(HttpMethod.GET) + .recordingStatusCallbackEvents(Promoter.listOfOne(Conference.RecordingEvent.IN_PROGRESS)) + .eventCallbackUrl(URI.create("https://example.com")) + .jitterBufferSize(Conference.JitterBufferSize.LARGE) + .participantLabel("participant_label") + .build(); + + Assert.assertEquals( + Conference.Builder.fromXml("name").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/ConnectTest.java b/src/test/java/com/twilio/twiml/voice/ConnectTest.java index 841878613d..3df1436ddb 100644 --- a/src/test/java/com/twilio/twiml/voice/ConnectTest.java +++ b/src/test/java/com/twilio/twiml/voice/ConnectTest.java @@ -173,4 +173,51 @@ public void testElementWithGenericNodeAttributes() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Connect elem = new Connect.Builder().action(URI.create("https://example.com")).method(HttpMethod.GET).build(); + + Assert.assertEquals( + Connect.Builder.fromXml("").build().toXml(), + elem.toXml() + ); + } + + @Test + public void testXmlChildrenDeserialization() { + final Connect.Builder builder = new Connect.Builder(); + + builder.room(new Room.Builder("name").participantIdentity("participant_identity").build()); + + builder.autopilot(new Autopilot.Builder("name").build()); + + builder.stream(new Stream.Builder() + .name("name") + .connectorName("connector_name") + .url("url") + .track(Stream.Track.INBOUND_TRACK) + .statusCallback("status_callback") + .statusCallbackMethod(Stream.StatusCallbackMethod.GET) + .build()); + + builder.virtualAgent(new VirtualAgent.Builder() + .connectorName("connector_name") + .language("language") + .sentimentAnalysis(true) + .statusCallback("status_callback") + .build()); + + final Connect elem = builder.build(); + + Assert.assertEquals( + Connect.Builder.fromXml("" + + "name" + + "name" + + "" + + "" + + "").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/DialTest.java b/src/test/java/com/twilio/twiml/voice/DialTest.java index feb939ce76..3110e78ec2 100644 --- a/src/test/java/com/twilio/twiml/voice/DialTest.java +++ b/src/test/java/com/twilio/twiml/voice/DialTest.java @@ -235,4 +235,111 @@ public void testElementWithGenericNodeAttributes() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Dial elem = new Dial.Builder("number") + .action(URI.create("https://example.com")) + .method(HttpMethod.GET) + .timeout(1) + .hangupOnStar(true) + .timeLimit(1) + .callerId("caller_id") + .record(Dial.Record.DO_NOT_RECORD) + .trim(Dial.Trim.TRIM_SILENCE) + .recordingStatusCallback(URI.create("https://example.com")) + .recordingStatusCallbackMethod(HttpMethod.GET) + .recordingStatusCallbackEvents(Promoter.listOfOne(Dial.RecordingEvent.IN_PROGRESS)) + .answerOnBridge(true) + .ringTone(Dial.RingTone.AT) + .recordingTrack(Dial.RecordingTrack.BOTH) + .sequential(true) + .referUrl(URI.create("https://example.com")) + .referMethod(HttpMethod.GET) + .build(); + + Assert.assertEquals( + Dial.Builder.fromXml("number").build().toXml(), + elem.toXml() + ); + } + + @Test + public void testXmlChildrenDeserialization() { + final Dial.Builder builder = new Dial.Builder(); + + builder.client(new Client.Builder("identity") + .url(URI.create("https://example.com")) + .method(HttpMethod.GET) + .statusCallbackEvents(Promoter.listOfOne(Client.Event.INITIATED)) + .statusCallback(URI.create("https://example.com")) + .statusCallbackMethod(HttpMethod.GET) + .build()); + + builder.conference(new Conference.Builder("name") + .muted(true) + .beep(Conference.Beep.TRUE) + .startConferenceOnEnter(true) + .endConferenceOnExit(true) + .waitUrl(URI.create("https://example.com")) + .waitMethod(HttpMethod.GET) + .maxParticipants(1) + .record(Conference.Record.DO_NOT_RECORD) + .region(Conference.Region.US1) + .coach("CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") + .trim(Conference.Trim.TRIM_SILENCE) + .statusCallbackEvents(Promoter.listOfOne(Conference.Event.START)) + .statusCallback(URI.create("https://example.com")) + .statusCallbackMethod(HttpMethod.GET) + .recordingStatusCallback(URI.create("https://example.com")) + .recordingStatusCallbackMethod(HttpMethod.GET) + .recordingStatusCallbackEvents(Promoter.listOfOne(Conference.RecordingEvent.IN_PROGRESS)) + .eventCallbackUrl(URI.create("https://example.com")) + .jitterBufferSize(Conference.JitterBufferSize.LARGE) + .participantLabel("participant_label") + .build()); + + builder.number(new Number.Builder(new com.twilio.type.PhoneNumber("+15017122661")) + .sendDigits("send_digits") + .url(URI.create("https://example.com")) + .method(HttpMethod.GET) + .statusCallbackEvents(Promoter.listOfOne(Number.Event.INITIATED)) + .statusCallback(URI.create("https://example.com")) + .statusCallbackMethod(HttpMethod.GET) + .byoc("BYXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") + .build()); + + builder.queue(new Queue.Builder("name") + .url(URI.create("https://example.com")) + .method(HttpMethod.GET) + .reservationSid("reservation_sid") + .postWorkActivitySid("post_work_activity_sid") + .build()); + + builder.sim(new Sim.Builder("DEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX").build()); + + builder.sip(new Sip.Builder(URI.create("https://example.com")) + .username("username") + .password("password") + .url(URI.create("https://example.com")) + .method(HttpMethod.GET) + .statusCallbackEvents(Promoter.listOfOne(Sip.Event.INITIATED)) + .statusCallback(URI.create("https://example.com")) + .statusCallbackMethod(HttpMethod.GET) + .build()); + + final Dial elem = builder.build(); + + Assert.assertEquals( + Dial.Builder.fromXml("" + + "identity" + + "name" + + "+15017122661" + + "name" + + "DEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" + + "https://example.com" + + "").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/EchoTest.java b/src/test/java/com/twilio/twiml/voice/EchoTest.java index 7f861b60d0..8888655ef9 100644 --- a/src/test/java/com/twilio/twiml/voice/EchoTest.java +++ b/src/test/java/com/twilio/twiml/voice/EchoTest.java @@ -102,4 +102,14 @@ public void testElementWithGenericNode() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Echo elem = new Echo.Builder().build(); + + Assert.assertEquals( + Echo.Builder.fromXml("").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/EnqueueTest.java b/src/test/java/com/twilio/twiml/voice/EnqueueTest.java index 2cb6a7168e..c36953c2f8 100644 --- a/src/test/java/com/twilio/twiml/voice/EnqueueTest.java +++ b/src/test/java/com/twilio/twiml/voice/EnqueueTest.java @@ -158,4 +158,36 @@ public void testElementWithGenericNodeAttributes() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Enqueue elem = new Enqueue.Builder("name") + .action(URI.create("https://example.com")) + .method(HttpMethod.GET) + .waitUrl(URI.create("https://example.com")) + .waitUrlMethod(HttpMethod.GET) + .workflowSid("workflow_sid") + .build(); + + Assert.assertEquals( + Enqueue.Builder.fromXml("name").build().toXml(), + elem.toXml() + ); + } + + @Test + public void testXmlChildrenDeserialization() { + final Enqueue.Builder builder = new Enqueue.Builder(); + + builder.task(new Task.Builder("body").priority(1).timeout(1).build()); + + final Enqueue elem = builder.build(); + + Assert.assertEquals( + Enqueue.Builder.fromXml("" + + "body" + + "").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/GatherTest.java b/src/test/java/com/twilio/twiml/voice/GatherTest.java index fd43943d66..09174e4783 100644 --- a/src/test/java/com/twilio/twiml/voice/GatherTest.java +++ b/src/test/java/com/twilio/twiml/voice/GatherTest.java @@ -179,4 +179,55 @@ public void testElementWithGenericNodeAttributes() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Gather elem = new Gather.Builder() + .inputs(Promoter.listOfOne(Gather.Input.DTMF)) + .action(URI.create("https://example.com")) + .method(HttpMethod.GET) + .timeout(1) + .speechTimeout("speech_timeout") + .maxSpeechTime(1) + .profanityFilter(true) + .finishOnKey("finish_on_key") + .numDigits(1) + .partialResultCallback(URI.create("https://example.com")) + .partialResultCallbackMethod(HttpMethod.GET) + .language(Gather.Language.AF_ZA) + .hints("hints") + .bargeIn(true) + .debug(true) + .actionOnEmptyResult(true) + .speechModel(Gather.SpeechModel.DEFAULT) + .enhanced(true) + .build(); + + Assert.assertEquals( + Gather.Builder.fromXml("").build().toXml(), + elem.toXml() + ); + } + + @Test + public void testXmlChildrenDeserialization() { + final Gather.Builder builder = new Gather.Builder(); + + builder.say(new Say.Builder("message").voice(Say.Voice.MAN).loop(1).language(Say.Language.ARB).build()); + + builder.pause(new Pause.Builder().length(1).build()); + + builder.play(new Play.Builder(URI.create("https://example.com")).loop(1).digits("digits").build()); + + final Gather elem = builder.build(); + + Assert.assertEquals( + Gather.Builder.fromXml("" + + "message" + + "" + + "https://example.com" + + "").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/HangupTest.java b/src/test/java/com/twilio/twiml/voice/HangupTest.java index 03efced79a..9004595a5b 100644 --- a/src/test/java/com/twilio/twiml/voice/HangupTest.java +++ b/src/test/java/com/twilio/twiml/voice/HangupTest.java @@ -102,4 +102,14 @@ public void testElementWithGenericNode() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Hangup elem = new Hangup.Builder().build(); + + Assert.assertEquals( + Hangup.Builder.fromXml("").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/IdentityTest.java b/src/test/java/com/twilio/twiml/voice/IdentityTest.java index 2abe29a3ef..bd9e751947 100644 --- a/src/test/java/com/twilio/twiml/voice/IdentityTest.java +++ b/src/test/java/com/twilio/twiml/voice/IdentityTest.java @@ -24,4 +24,14 @@ public void testElementWithParams() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Identity elem = new Identity.Builder("client_identity").build(); + + Assert.assertEquals( + Identity.Builder.fromXml("client_identity").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/LeaveTest.java b/src/test/java/com/twilio/twiml/voice/LeaveTest.java index 1db1a12727..dac0ea50a3 100644 --- a/src/test/java/com/twilio/twiml/voice/LeaveTest.java +++ b/src/test/java/com/twilio/twiml/voice/LeaveTest.java @@ -102,4 +102,14 @@ public void testElementWithGenericNode() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Leave elem = new Leave.Builder().build(); + + Assert.assertEquals( + Leave.Builder.fromXml("").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/NumberTest.java b/src/test/java/com/twilio/twiml/voice/NumberTest.java index a20593002b..c80cea4543 100644 --- a/src/test/java/com/twilio/twiml/voice/NumberTest.java +++ b/src/test/java/com/twilio/twiml/voice/NumberTest.java @@ -37,4 +37,22 @@ public void testElementWithParams() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Number elem = new Number.Builder(new com.twilio.type.PhoneNumber("+15017122661")) + .sendDigits("send_digits") + .url(URI.create("https://example.com")) + .method(HttpMethod.GET) + .statusCallbackEvents(Promoter.listOfOne(Number.Event.INITIATED)) + .statusCallback(URI.create("https://example.com")) + .statusCallbackMethod(HttpMethod.GET) + .byoc("BYXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") + .build(); + + Assert.assertEquals( + Number.Builder.fromXml("+15017122661").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/ParameterTest.java b/src/test/java/com/twilio/twiml/voice/ParameterTest.java index cc1ce002f4..e7e978c8d9 100644 --- a/src/test/java/com/twilio/twiml/voice/ParameterTest.java +++ b/src/test/java/com/twilio/twiml/voice/ParameterTest.java @@ -113,4 +113,14 @@ public void testElementWithGenericNode() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Parameter elem = new Parameter.Builder().name("name").value("value").build(); + + Assert.assertEquals( + Parameter.Builder.fromXml("").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/PauseTest.java b/src/test/java/com/twilio/twiml/voice/PauseTest.java index d97f7ae9f3..0659ebb54a 100644 --- a/src/test/java/com/twilio/twiml/voice/PauseTest.java +++ b/src/test/java/com/twilio/twiml/voice/PauseTest.java @@ -113,4 +113,14 @@ public void testElementWithGenericNode() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Pause elem = new Pause.Builder().length(1).build(); + + Assert.assertEquals( + Pause.Builder.fromXml("").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/PayTest.java b/src/test/java/com/twilio/twiml/voice/PayTest.java index 7aebb9dc99..5d980e5afb 100644 --- a/src/test/java/com/twilio/twiml/voice/PayTest.java +++ b/src/test/java/com/twilio/twiml/voice/PayTest.java @@ -180,4 +180,57 @@ public void testElementWithGenericNodeAttributes() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Pay elem = new Pay.Builder() + .input(Pay.Input.DTMF) + .action(URI.create("https://example.com")) + .bankAccountType(Pay.BankAccountType.CONSUMER_CHECKING) + .statusCallback(URI.create("https://example.com")) + .statusCallbackMethod(Pay.StatusCallbackMethod.GET) + .timeout(1) + .maxAttempts(1) + .securityCode(true) + .postalCode("postal_code") + .minPostalCodeLength(1) + .paymentConnector("payment_connector") + .paymentMethod(Pay.PaymentMethod.ACH_DEBIT) + .tokenType(Pay.TokenType.ONE_TIME) + .chargeAmount("charge_amount") + .currency("currency") + .description("description") + .validCardTypes(Promoter.listOfOne(Pay.ValidCardTypes.VISA)) + .language(Pay.Language.DE_DE) + .build(); + + Assert.assertEquals( + Pay.Builder.fromXml("").build().toXml(), + elem.toXml() + ); + } + + @Test + public void testXmlChildrenDeserialization() { + final Pay.Builder builder = new Pay.Builder(); + + builder.prompt(new Prompt.Builder() + .for_(Prompt.For.PAYMENT_CARD_NUMBER) + .errorTypes(Promoter.listOfOne(Prompt.ErrorType.TIMEOUT)) + .cardTypes(Promoter.listOfOne(Prompt.CardType.VISA)) + .attempts(Promoter.listOfOne(1)) + .build()); + + builder.parameter(new Parameter.Builder().name("name").value("value").build()); + + final Pay elem = builder.build(); + + Assert.assertEquals( + Pay.Builder.fromXml("" + + "" + + "" + + "").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/PlayTest.java b/src/test/java/com/twilio/twiml/voice/PlayTest.java index b646ea5664..c9734b80a5 100644 --- a/src/test/java/com/twilio/twiml/voice/PlayTest.java +++ b/src/test/java/com/twilio/twiml/voice/PlayTest.java @@ -26,4 +26,14 @@ public void testElementWithParams() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Play elem = new Play.Builder(URI.create("https://example.com")).loop(1).digits("digits").build(); + + Assert.assertEquals( + Play.Builder.fromXml("https://example.com").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/PromptTest.java b/src/test/java/com/twilio/twiml/voice/PromptTest.java index dbe88ac19f..fc23b38b92 100644 --- a/src/test/java/com/twilio/twiml/voice/PromptTest.java +++ b/src/test/java/com/twilio/twiml/voice/PromptTest.java @@ -164,4 +164,41 @@ public void testElementWithGenericNodeAttributes() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Prompt elem = new Prompt.Builder() + .for_(Prompt.For.PAYMENT_CARD_NUMBER) + .errorTypes(Promoter.listOfOne(Prompt.ErrorType.TIMEOUT)) + .cardTypes(Promoter.listOfOne(Prompt.CardType.VISA)) + .attempts(Promoter.listOfOne(1)) + .build(); + + Assert.assertEquals( + Prompt.Builder.fromXml("").build().toXml(), + elem.toXml() + ); + } + + @Test + public void testXmlChildrenDeserialization() { + final Prompt.Builder builder = new Prompt.Builder(); + + builder.say(new Say.Builder("message").voice(Say.Voice.MAN).loop(1).language(Say.Language.ARB).build()); + + builder.play(new Play.Builder(URI.create("https://example.com")).loop(1).digits("digits").build()); + + builder.pause(new Pause.Builder().length(1).build()); + + final Prompt elem = builder.build(); + + Assert.assertEquals( + Prompt.Builder.fromXml("" + + "message" + + "https://example.com" + + "" + + "").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/QueueTest.java b/src/test/java/com/twilio/twiml/voice/QueueTest.java index aebec7a74a..48454e00ad 100644 --- a/src/test/java/com/twilio/twiml/voice/QueueTest.java +++ b/src/test/java/com/twilio/twiml/voice/QueueTest.java @@ -32,4 +32,19 @@ public void testElementWithParams() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Queue elem = new Queue.Builder("name") + .url(URI.create("https://example.com")) + .method(HttpMethod.GET) + .reservationSid("reservation_sid") + .postWorkActivitySid("post_work_activity_sid") + .build(); + + Assert.assertEquals( + Queue.Builder.fromXml("name").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/RecordTest.java b/src/test/java/com/twilio/twiml/voice/RecordTest.java index b9565e9899..b6769cb50e 100644 --- a/src/test/java/com/twilio/twiml/voice/RecordTest.java +++ b/src/test/java/com/twilio/twiml/voice/RecordTest.java @@ -131,4 +131,27 @@ public void testElementWithGenericNode() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Record elem = new Record.Builder() + .action(URI.create("https://example.com")) + .method(HttpMethod.GET) + .timeout(1) + .finishOnKey("finish_on_key") + .maxLength(1) + .playBeep(true) + .trim(Record.Trim.TRIM_SILENCE) + .recordingStatusCallback(URI.create("https://example.com")) + .recordingStatusCallbackMethod(HttpMethod.GET) + .recordingStatusCallbackEvents(Promoter.listOfOne(Record.RecordingEvent.IN_PROGRESS)) + .transcribe(true) + .transcribeCallback(URI.create("https://example.com")) + .build(); + + Assert.assertEquals( + Record.Builder.fromXml("").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/RedirectTest.java b/src/test/java/com/twilio/twiml/voice/RedirectTest.java index 3cc9d32edb..9268810664 100644 --- a/src/test/java/com/twilio/twiml/voice/RedirectTest.java +++ b/src/test/java/com/twilio/twiml/voice/RedirectTest.java @@ -27,4 +27,14 @@ public void testElementWithParams() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Redirect elem = new Redirect.Builder(URI.create("https://example.com")).method(HttpMethod.GET).build(); + + Assert.assertEquals( + Redirect.Builder.fromXml("https://example.com").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/ReferSipTest.java b/src/test/java/com/twilio/twiml/voice/ReferSipTest.java index 3e9435bcda..941ca0fdcf 100644 --- a/src/test/java/com/twilio/twiml/voice/ReferSipTest.java +++ b/src/test/java/com/twilio/twiml/voice/ReferSipTest.java @@ -26,4 +26,14 @@ public void testElementWithParams() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final ReferSip elem = new ReferSip.Builder(URI.create("https://example.com")).build(); + + Assert.assertEquals( + ReferSip.Builder.fromXml("https://example.com").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/ReferTest.java b/src/test/java/com/twilio/twiml/voice/ReferTest.java index 7f03c21679..6c880d41e0 100644 --- a/src/test/java/com/twilio/twiml/voice/ReferTest.java +++ b/src/test/java/com/twilio/twiml/voice/ReferTest.java @@ -152,4 +152,30 @@ public void testElementWithGenericNodeAttributes() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Refer elem = new Refer.Builder().action(URI.create("https://example.com")).method(HttpMethod.GET).build(); + + Assert.assertEquals( + Refer.Builder.fromXml("").build().toXml(), + elem.toXml() + ); + } + + @Test + public void testXmlChildrenDeserialization() { + final Refer.Builder builder = new Refer.Builder(); + + builder.sip(new ReferSip.Builder(URI.create("https://example.com")).build()); + + final Refer elem = builder.build(); + + Assert.assertEquals( + Refer.Builder.fromXml("" + + "https://example.com" + + "").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/RejectTest.java b/src/test/java/com/twilio/twiml/voice/RejectTest.java index fbb2a9a8d8..4c3aad7143 100644 --- a/src/test/java/com/twilio/twiml/voice/RejectTest.java +++ b/src/test/java/com/twilio/twiml/voice/RejectTest.java @@ -113,4 +113,14 @@ public void testElementWithGenericNode() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Reject elem = new Reject.Builder().reason(Reject.Reason.REJECTED).build(); + + Assert.assertEquals( + Reject.Builder.fromXml("").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/RoomTest.java b/src/test/java/com/twilio/twiml/voice/RoomTest.java index 5e4058a704..e5a7f32c11 100644 --- a/src/test/java/com/twilio/twiml/voice/RoomTest.java +++ b/src/test/java/com/twilio/twiml/voice/RoomTest.java @@ -24,4 +24,14 @@ public void testElementWithParams() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Room elem = new Room.Builder("name").participantIdentity("participant_identity").build(); + + Assert.assertEquals( + Room.Builder.fromXml("name").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/SayTest.java b/src/test/java/com/twilio/twiml/voice/SayTest.java index 96ee5d9bbb..1b859f877b 100644 --- a/src/test/java/com/twilio/twiml/voice/SayTest.java +++ b/src/test/java/com/twilio/twiml/voice/SayTest.java @@ -179,4 +179,60 @@ public void testElementWithGenericNodeAttributes() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Say elem = new Say.Builder("message").voice(Say.Voice.MAN).loop(1).language(Say.Language.ARB).build(); + + Assert.assertEquals( + Say.Builder.fromXml("message").build().toXml(), + elem.toXml() + ); + } + + @Test + public void testXmlChildrenDeserialization() { + final Say.Builder builder = new Say.Builder(); + + builder.break_(new SsmlBreak.Builder().strength(SsmlBreak.Strength.NONE).time("time").build()); + + builder.emphasis(new SsmlEmphasis.Builder("words").level(SsmlEmphasis.Level.STRONG).build()); + + builder.lang(new SsmlLang.Builder("words").xmlLang(SsmlLang.XmlLang.DA_DK).build()); + + builder.p(new SsmlP.Builder("words").build()); + + builder.phoneme(new SsmlPhoneme.Builder("words").alphabet(SsmlPhoneme.Alphabet.IPA).ph("ph").build()); + + builder.prosody(new SsmlProsody.Builder("words").volume("volume").rate("rate").pitch("pitch").build()); + + builder.s(new SsmlS.Builder("words").build()); + + builder.sayAs(new SsmlSayAs.Builder("words") + .interpretAs(SsmlSayAs.InterpretAs.CHARACTER) + .role(SsmlSayAs.Role.MDY) + .build()); + + builder.sub(new SsmlSub.Builder("words").alias("alias").build()); + + builder.w(new SsmlW.Builder("words").role("role").build()); + + final Say elem = builder.build(); + + Assert.assertEquals( + Say.Builder.fromXml("" + + "" + + "words" + + "words" + + "

words

" + + "words" + + "words" + + "words" + + "words" + + "words" + + "words" + + "
").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/SimTest.java b/src/test/java/com/twilio/twiml/voice/SimTest.java index 0a420fe7d2..bc3a00c2a3 100644 --- a/src/test/java/com/twilio/twiml/voice/SimTest.java +++ b/src/test/java/com/twilio/twiml/voice/SimTest.java @@ -24,4 +24,14 @@ public void testElementWithParams() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Sim elem = new Sim.Builder("DEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX").build(); + + Assert.assertEquals( + Sim.Builder.fromXml("DEXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/SipTest.java b/src/test/java/com/twilio/twiml/voice/SipTest.java index cf9d216a3a..28fd726c21 100644 --- a/src/test/java/com/twilio/twiml/voice/SipTest.java +++ b/src/test/java/com/twilio/twiml/voice/SipTest.java @@ -37,4 +37,22 @@ public void testElementWithParams() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Sip elem = new Sip.Builder(URI.create("https://example.com")) + .username("username") + .password("password") + .url(URI.create("https://example.com")) + .method(HttpMethod.GET) + .statusCallbackEvents(Promoter.listOfOne(Sip.Event.INITIATED)) + .statusCallback(URI.create("https://example.com")) + .statusCallbackMethod(HttpMethod.GET) + .build(); + + Assert.assertEquals( + Sip.Builder.fromXml("https://example.com").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/SiprecTest.java b/src/test/java/com/twilio/twiml/voice/SiprecTest.java index e43934ee8f..633872337a 100644 --- a/src/test/java/com/twilio/twiml/voice/SiprecTest.java +++ b/src/test/java/com/twilio/twiml/voice/SiprecTest.java @@ -153,4 +153,34 @@ public void testElementWithGenericNodeAttributes() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Siprec elem = new Siprec.Builder() + .name("name") + .connectorName("connector_name") + .track(Siprec.Track.INBOUND_TRACK) + .build(); + + Assert.assertEquals( + Siprec.Builder.fromXml("").build().toXml(), + elem.toXml() + ); + } + + @Test + public void testXmlChildrenDeserialization() { + final Siprec.Builder builder = new Siprec.Builder(); + + builder.parameter(new Parameter.Builder().name("name").value("value").build()); + + final Siprec elem = builder.build(); + + Assert.assertEquals( + Siprec.Builder.fromXml("" + + "" + + "").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/SmsTest.java b/src/test/java/com/twilio/twiml/voice/SmsTest.java index c8110a4ad1..cf3c72466d 100644 --- a/src/test/java/com/twilio/twiml/voice/SmsTest.java +++ b/src/test/java/com/twilio/twiml/voice/SmsTest.java @@ -33,4 +33,20 @@ public void testElementWithParams() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Sms elem = new Sms.Builder("message") + .to(new com.twilio.type.PhoneNumber("+15558675310")) + .from(new com.twilio.type.PhoneNumber("+15017122661")) + .action(URI.create("https://example.com")) + .method(HttpMethod.GET) + .statusCallback(URI.create("https://example.com")) + .build(); + + Assert.assertEquals( + Sms.Builder.fromXml("message").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/SsmlBreakTest.java b/src/test/java/com/twilio/twiml/voice/SsmlBreakTest.java index 3964369911..837fbe4b11 100644 --- a/src/test/java/com/twilio/twiml/voice/SsmlBreakTest.java +++ b/src/test/java/com/twilio/twiml/voice/SsmlBreakTest.java @@ -113,4 +113,14 @@ public void testElementWithGenericNode() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final SsmlBreak elem = new SsmlBreak.Builder().strength(SsmlBreak.Strength.NONE).time("time").build(); + + Assert.assertEquals( + SsmlBreak.Builder.fromXml("").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/SsmlEmphasisTest.java b/src/test/java/com/twilio/twiml/voice/SsmlEmphasisTest.java index b360b09f37..55ff8af535 100644 --- a/src/test/java/com/twilio/twiml/voice/SsmlEmphasisTest.java +++ b/src/test/java/com/twilio/twiml/voice/SsmlEmphasisTest.java @@ -173,4 +173,54 @@ public void testElementWithGenericNodeAttributes() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final SsmlEmphasis elem = new SsmlEmphasis.Builder("words").level(SsmlEmphasis.Level.STRONG).build(); + + Assert.assertEquals( + SsmlEmphasis.Builder.fromXml("words").build().toXml(), + elem.toXml() + ); + } + + @Test + public void testXmlChildrenDeserialization() { + final SsmlEmphasis.Builder builder = new SsmlEmphasis.Builder(); + + builder.break_(new SsmlBreak.Builder().strength(SsmlBreak.Strength.NONE).time("time").build()); + + builder.emphasis(new SsmlEmphasis.Builder("words").level(SsmlEmphasis.Level.STRONG).build()); + + builder.lang(new SsmlLang.Builder("words").xmlLang(SsmlLang.XmlLang.DA_DK).build()); + + builder.phoneme(new SsmlPhoneme.Builder("words").alphabet(SsmlPhoneme.Alphabet.IPA).ph("ph").build()); + + builder.prosody(new SsmlProsody.Builder("words").volume("volume").rate("rate").pitch("pitch").build()); + + builder.sayAs(new SsmlSayAs.Builder("words") + .interpretAs(SsmlSayAs.InterpretAs.CHARACTER) + .role(SsmlSayAs.Role.MDY) + .build()); + + builder.sub(new SsmlSub.Builder("words").alias("alias").build()); + + builder.w(new SsmlW.Builder("words").role("role").build()); + + final SsmlEmphasis elem = builder.build(); + + Assert.assertEquals( + SsmlEmphasis.Builder.fromXml("" + + "" + + "words" + + "words" + + "words" + + "words" + + "words" + + "words" + + "words" + + "").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/SsmlLangTest.java b/src/test/java/com/twilio/twiml/voice/SsmlLangTest.java index 04c55911a9..0da17fcc00 100644 --- a/src/test/java/com/twilio/twiml/voice/SsmlLangTest.java +++ b/src/test/java/com/twilio/twiml/voice/SsmlLangTest.java @@ -179,4 +179,60 @@ public void testElementWithGenericNodeAttributes() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final SsmlLang elem = new SsmlLang.Builder("words").xmlLang(SsmlLang.XmlLang.DA_DK).build(); + + Assert.assertEquals( + SsmlLang.Builder.fromXml("words").build().toXml(), + elem.toXml() + ); + } + + @Test + public void testXmlChildrenDeserialization() { + final SsmlLang.Builder builder = new SsmlLang.Builder(); + + builder.break_(new SsmlBreak.Builder().strength(SsmlBreak.Strength.NONE).time("time").build()); + + builder.emphasis(new SsmlEmphasis.Builder("words").level(SsmlEmphasis.Level.STRONG).build()); + + builder.lang(new SsmlLang.Builder("words").xmlLang(SsmlLang.XmlLang.DA_DK).build()); + + builder.p(new SsmlP.Builder("words").build()); + + builder.phoneme(new SsmlPhoneme.Builder("words").alphabet(SsmlPhoneme.Alphabet.IPA).ph("ph").build()); + + builder.prosody(new SsmlProsody.Builder("words").volume("volume").rate("rate").pitch("pitch").build()); + + builder.s(new SsmlS.Builder("words").build()); + + builder.sayAs(new SsmlSayAs.Builder("words") + .interpretAs(SsmlSayAs.InterpretAs.CHARACTER) + .role(SsmlSayAs.Role.MDY) + .build()); + + builder.sub(new SsmlSub.Builder("words").alias("alias").build()); + + builder.w(new SsmlW.Builder("words").role("role").build()); + + final SsmlLang elem = builder.build(); + + Assert.assertEquals( + SsmlLang.Builder.fromXml("" + + "" + + "words" + + "words" + + "

words

" + + "words" + + "words" + + "words" + + "words" + + "words" + + "words" + + "
").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/SsmlPTest.java b/src/test/java/com/twilio/twiml/voice/SsmlPTest.java index 6332da7b21..c9ef72ca16 100644 --- a/src/test/java/com/twilio/twiml/voice/SsmlPTest.java +++ b/src/test/java/com/twilio/twiml/voice/SsmlPTest.java @@ -176,4 +176,57 @@ public void testElementWithGenericNodeAttributes() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final SsmlP elem = new SsmlP.Builder("words").build(); + + Assert.assertEquals( + SsmlP.Builder.fromXml("

words

").build().toXml(), + elem.toXml() + ); + } + + @Test + public void testXmlChildrenDeserialization() { + final SsmlP.Builder builder = new SsmlP.Builder(); + + builder.break_(new SsmlBreak.Builder().strength(SsmlBreak.Strength.NONE).time("time").build()); + + builder.emphasis(new SsmlEmphasis.Builder("words").level(SsmlEmphasis.Level.STRONG).build()); + + builder.lang(new SsmlLang.Builder("words").xmlLang(SsmlLang.XmlLang.DA_DK).build()); + + builder.phoneme(new SsmlPhoneme.Builder("words").alphabet(SsmlPhoneme.Alphabet.IPA).ph("ph").build()); + + builder.prosody(new SsmlProsody.Builder("words").volume("volume").rate("rate").pitch("pitch").build()); + + builder.s(new SsmlS.Builder("words").build()); + + builder.sayAs(new SsmlSayAs.Builder("words") + .interpretAs(SsmlSayAs.InterpretAs.CHARACTER) + .role(SsmlSayAs.Role.MDY) + .build()); + + builder.sub(new SsmlSub.Builder("words").alias("alias").build()); + + builder.w(new SsmlW.Builder("words").role("role").build()); + + final SsmlP elem = builder.build(); + + Assert.assertEquals( + SsmlP.Builder.fromXml("

" + + "" + + "words" + + "words" + + "words" + + "words" + + "words" + + "words" + + "words" + + "words" + + "

").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/SsmlPhonemeTest.java b/src/test/java/com/twilio/twiml/voice/SsmlPhonemeTest.java index 0cdbd72ea3..b8771ca205 100644 --- a/src/test/java/com/twilio/twiml/voice/SsmlPhonemeTest.java +++ b/src/test/java/com/twilio/twiml/voice/SsmlPhonemeTest.java @@ -24,4 +24,14 @@ public void testElementWithParams() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final SsmlPhoneme elem = new SsmlPhoneme.Builder("words").alphabet(SsmlPhoneme.Alphabet.IPA).ph("ph").build(); + + Assert.assertEquals( + SsmlPhoneme.Builder.fromXml("words").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/SsmlProsodyTest.java b/src/test/java/com/twilio/twiml/voice/SsmlProsodyTest.java index c80835ca3d..547c802e13 100644 --- a/src/test/java/com/twilio/twiml/voice/SsmlProsodyTest.java +++ b/src/test/java/com/twilio/twiml/voice/SsmlProsodyTest.java @@ -179,4 +179,60 @@ public void testElementWithGenericNodeAttributes() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final SsmlProsody elem = new SsmlProsody.Builder("words").volume("volume").rate("rate").pitch("pitch").build(); + + Assert.assertEquals( + SsmlProsody.Builder.fromXml("words").build().toXml(), + elem.toXml() + ); + } + + @Test + public void testXmlChildrenDeserialization() { + final SsmlProsody.Builder builder = new SsmlProsody.Builder(); + + builder.break_(new SsmlBreak.Builder().strength(SsmlBreak.Strength.NONE).time("time").build()); + + builder.emphasis(new SsmlEmphasis.Builder("words").level(SsmlEmphasis.Level.STRONG).build()); + + builder.lang(new SsmlLang.Builder("words").xmlLang(SsmlLang.XmlLang.DA_DK).build()); + + builder.p(new SsmlP.Builder("words").build()); + + builder.phoneme(new SsmlPhoneme.Builder("words").alphabet(SsmlPhoneme.Alphabet.IPA).ph("ph").build()); + + builder.prosody(new SsmlProsody.Builder("words").volume("volume").rate("rate").pitch("pitch").build()); + + builder.s(new SsmlS.Builder("words").build()); + + builder.sayAs(new SsmlSayAs.Builder("words") + .interpretAs(SsmlSayAs.InterpretAs.CHARACTER) + .role(SsmlSayAs.Role.MDY) + .build()); + + builder.sub(new SsmlSub.Builder("words").alias("alias").build()); + + builder.w(new SsmlW.Builder("words").role("role").build()); + + final SsmlProsody elem = builder.build(); + + Assert.assertEquals( + SsmlProsody.Builder.fromXml("" + + "" + + "words" + + "words" + + "

words

" + + "words" + + "words" + + "words" + + "words" + + "words" + + "words" + + "
").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/SsmlSTest.java b/src/test/java/com/twilio/twiml/voice/SsmlSTest.java index 411ff452f0..1a19f8924e 100644 --- a/src/test/java/com/twilio/twiml/voice/SsmlSTest.java +++ b/src/test/java/com/twilio/twiml/voice/SsmlSTest.java @@ -173,4 +173,54 @@ public void testElementWithGenericNodeAttributes() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final SsmlS elem = new SsmlS.Builder("words").build(); + + Assert.assertEquals( + SsmlS.Builder.fromXml("words").build().toXml(), + elem.toXml() + ); + } + + @Test + public void testXmlChildrenDeserialization() { + final SsmlS.Builder builder = new SsmlS.Builder(); + + builder.break_(new SsmlBreak.Builder().strength(SsmlBreak.Strength.NONE).time("time").build()); + + builder.emphasis(new SsmlEmphasis.Builder("words").level(SsmlEmphasis.Level.STRONG).build()); + + builder.lang(new SsmlLang.Builder("words").xmlLang(SsmlLang.XmlLang.DA_DK).build()); + + builder.phoneme(new SsmlPhoneme.Builder("words").alphabet(SsmlPhoneme.Alphabet.IPA).ph("ph").build()); + + builder.prosody(new SsmlProsody.Builder("words").volume("volume").rate("rate").pitch("pitch").build()); + + builder.sayAs(new SsmlSayAs.Builder("words") + .interpretAs(SsmlSayAs.InterpretAs.CHARACTER) + .role(SsmlSayAs.Role.MDY) + .build()); + + builder.sub(new SsmlSub.Builder("words").alias("alias").build()); + + builder.w(new SsmlW.Builder("words").role("role").build()); + + final SsmlS elem = builder.build(); + + Assert.assertEquals( + SsmlS.Builder.fromXml("" + + "" + + "words" + + "words" + + "words" + + "words" + + "words" + + "words" + + "words" + + "").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/SsmlSayAsTest.java b/src/test/java/com/twilio/twiml/voice/SsmlSayAsTest.java index d874782b50..442abd67f7 100644 --- a/src/test/java/com/twilio/twiml/voice/SsmlSayAsTest.java +++ b/src/test/java/com/twilio/twiml/voice/SsmlSayAsTest.java @@ -27,4 +27,17 @@ public void testElementWithParams() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final SsmlSayAs elem = new SsmlSayAs.Builder("words") + .interpretAs(SsmlSayAs.InterpretAs.CHARACTER) + .role(SsmlSayAs.Role.MDY) + .build(); + + Assert.assertEquals( + SsmlSayAs.Builder.fromXml("words").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/SsmlSubTest.java b/src/test/java/com/twilio/twiml/voice/SsmlSubTest.java index cc1ca5a831..638948b6ec 100644 --- a/src/test/java/com/twilio/twiml/voice/SsmlSubTest.java +++ b/src/test/java/com/twilio/twiml/voice/SsmlSubTest.java @@ -24,4 +24,14 @@ public void testElementWithParams() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final SsmlSub elem = new SsmlSub.Builder("words").alias("alias").build(); + + Assert.assertEquals( + SsmlSub.Builder.fromXml("words").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/SsmlWTest.java b/src/test/java/com/twilio/twiml/voice/SsmlWTest.java index cce59474fb..305aeed2af 100644 --- a/src/test/java/com/twilio/twiml/voice/SsmlWTest.java +++ b/src/test/java/com/twilio/twiml/voice/SsmlWTest.java @@ -167,4 +167,48 @@ public void testElementWithGenericNodeAttributes() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final SsmlW elem = new SsmlW.Builder("words").role("role").build(); + + Assert.assertEquals( + SsmlW.Builder.fromXml("words").build().toXml(), + elem.toXml() + ); + } + + @Test + public void testXmlChildrenDeserialization() { + final SsmlW.Builder builder = new SsmlW.Builder(); + + builder.break_(new SsmlBreak.Builder().strength(SsmlBreak.Strength.NONE).time("time").build()); + + builder.emphasis(new SsmlEmphasis.Builder("words").level(SsmlEmphasis.Level.STRONG).build()); + + builder.phoneme(new SsmlPhoneme.Builder("words").alphabet(SsmlPhoneme.Alphabet.IPA).ph("ph").build()); + + builder.prosody(new SsmlProsody.Builder("words").volume("volume").rate("rate").pitch("pitch").build()); + + builder.sayAs(new SsmlSayAs.Builder("words") + .interpretAs(SsmlSayAs.InterpretAs.CHARACTER) + .role(SsmlSayAs.Role.MDY) + .build()); + + builder.sub(new SsmlSub.Builder("words").alias("alias").build()); + + final SsmlW elem = builder.build(); + + Assert.assertEquals( + SsmlW.Builder.fromXml("" + + "" + + "words" + + "words" + + "words" + + "words" + + "words" + + "").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/StartTest.java b/src/test/java/com/twilio/twiml/voice/StartTest.java index 8bf7cefc1b..b1fad5abd8 100644 --- a/src/test/java/com/twilio/twiml/voice/StartTest.java +++ b/src/test/java/com/twilio/twiml/voice/StartTest.java @@ -166,4 +166,44 @@ public void testElementWithGenericNodeAttributes() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Start elem = new Start.Builder().action(URI.create("https://example.com")).method(HttpMethod.GET).build(); + + Assert.assertEquals( + Start.Builder.fromXml("").build().toXml(), + elem.toXml() + ); + } + + @Test + public void testXmlChildrenDeserialization() { + final Start.Builder builder = new Start.Builder(); + + builder.stream(new Stream.Builder() + .name("name") + .connectorName("connector_name") + .url("url") + .track(Stream.Track.INBOUND_TRACK) + .statusCallback("status_callback") + .statusCallbackMethod(Stream.StatusCallbackMethod.GET) + .build()); + + builder.siprec(new Siprec.Builder() + .name("name") + .connectorName("connector_name") + .track(Siprec.Track.INBOUND_TRACK) + .build()); + + final Start elem = builder.build(); + + Assert.assertEquals( + Start.Builder.fromXml("" + + "" + + "" + + "").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/StopTest.java b/src/test/java/com/twilio/twiml/voice/StopTest.java index 47930cdd85..ef3b82fb6c 100644 --- a/src/test/java/com/twilio/twiml/voice/StopTest.java +++ b/src/test/java/com/twilio/twiml/voice/StopTest.java @@ -152,4 +152,44 @@ public void testElementWithGenericNodeAttributes() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Stop elem = new Stop.Builder().build(); + + Assert.assertEquals( + Stop.Builder.fromXml("").build().toXml(), + elem.toXml() + ); + } + + @Test + public void testXmlChildrenDeserialization() { + final Stop.Builder builder = new Stop.Builder(); + + builder.stream(new Stream.Builder() + .name("name") + .connectorName("connector_name") + .url("url") + .track(Stream.Track.INBOUND_TRACK) + .statusCallback("status_callback") + .statusCallbackMethod(Stream.StatusCallbackMethod.GET) + .build()); + + builder.siprec(new Siprec.Builder() + .name("name") + .connectorName("connector_name") + .track(Siprec.Track.INBOUND_TRACK) + .build()); + + final Stop elem = builder.build(); + + Assert.assertEquals( + Stop.Builder.fromXml("" + + "" + + "" + + "").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/StreamTest.java b/src/test/java/com/twilio/twiml/voice/StreamTest.java index b11813c0e8..1ea236f9d6 100644 --- a/src/test/java/com/twilio/twiml/voice/StreamTest.java +++ b/src/test/java/com/twilio/twiml/voice/StreamTest.java @@ -156,4 +156,37 @@ public void testElementWithGenericNodeAttributes() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Stream elem = new Stream.Builder() + .name("name") + .connectorName("connector_name") + .url("url") + .track(Stream.Track.INBOUND_TRACK) + .statusCallback("status_callback") + .statusCallbackMethod(Stream.StatusCallbackMethod.GET) + .build(); + + Assert.assertEquals( + Stream.Builder.fromXml("").build().toXml(), + elem.toXml() + ); + } + + @Test + public void testXmlChildrenDeserialization() { + final Stream.Builder builder = new Stream.Builder(); + + builder.parameter(new Parameter.Builder().name("name").value("value").build()); + + final Stream elem = builder.build(); + + Assert.assertEquals( + Stream.Builder.fromXml("" + + "" + + "").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/TaskTest.java b/src/test/java/com/twilio/twiml/voice/TaskTest.java index 71a01cda95..c2e2476b9f 100644 --- a/src/test/java/com/twilio/twiml/voice/TaskTest.java +++ b/src/test/java/com/twilio/twiml/voice/TaskTest.java @@ -24,4 +24,14 @@ public void testElementWithParams() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final Task elem = new Task.Builder("body").priority(1).timeout(1).build(); + + Assert.assertEquals( + Task.Builder.fromXml("body").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file diff --git a/src/test/java/com/twilio/twiml/voice/VirtualAgentTest.java b/src/test/java/com/twilio/twiml/voice/VirtualAgentTest.java index 1feeed51d3..4b749b51c4 100644 --- a/src/test/java/com/twilio/twiml/voice/VirtualAgentTest.java +++ b/src/test/java/com/twilio/twiml/voice/VirtualAgentTest.java @@ -118,4 +118,19 @@ public void testElementWithGenericNode() { elem.toXml() ); } + + @Test + public void testXmlAttributesDeserialization() { + final VirtualAgent elem = new VirtualAgent.Builder() + .connectorName("connector_name") + .language("language") + .sentimentAnalysis(true) + .statusCallback("status_callback") + .build(); + + Assert.assertEquals( + VirtualAgent.Builder.fromXml("").build().toXml(), + elem.toXml() + ); + } } \ No newline at end of file