001/*
002 *   Copyright 2020 Vonage
003 *
004 *   Licensed under the Apache License, Version 2.0 (the "License");
005 *   you may not use this file except in compliance with the License.
006 *   You may obtain a copy of the License at
007 *
008 *        http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *   Unless required by applicable law or agreed to in writing, software
011 *   distributed under the License is distributed on an "AS IS" BASIS,
012 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *   See the License for the specific language governing permissions and
014 *   limitations under the License.
015 */
016package com.vonage.client.sms;
017
018import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
019import com.fasterxml.jackson.annotation.JsonProperty;
020import com.fasterxml.jackson.databind.JsonMappingException;
021import com.fasterxml.jackson.databind.ObjectMapper;
022import com.vonage.client.VonageResponseParseException;
023import com.vonage.client.VonageUnexpectedException;
024
025import java.io.IOException;
026import java.util.List;
027
028@JsonIgnoreProperties(ignoreUnknown = true)
029public class SmsSubmissionResponse {
030    @JsonProperty("message-count")
031    private int messageCount;
032
033    @JsonProperty("messages")
034    private List<SmsSubmissionResponseMessage> messages;
035
036    public static SmsSubmissionResponse fromJson(String json) {
037        try {
038            ObjectMapper mapper = new ObjectMapper();
039            return mapper.readValue(json, SmsSubmissionResponse.class);
040        } catch (JsonMappingException jme) {
041            throw new VonageResponseParseException("Failed to produce SmsSubmissionResponse from json.", jme);
042        } catch (IOException jpe) {
043            throw new VonageUnexpectedException("Failed to produce SmsSubmissionResponse from json.", jpe);
044        }
045    }
046
047    public int getMessageCount() {
048        return this.messageCount;
049    }
050
051    public List<SmsSubmissionResponseMessage> getMessages() {
052        return this.messages;
053    }
054}