Skip to content

Commit

Permalink
Merge pull request #225 from sccalabr/mailTest
Browse files Browse the repository at this point in the history
Fixing Mail deserialization issue.
  • Loading branch information
thinkingserious authored Nov 28, 2017
2 parents fe032c9 + 22ba9e9 commit 4d58fcb
Show file tree
Hide file tree
Showing 17 changed files with 678 additions and 552 deletions.
114 changes: 92 additions & 22 deletions src/main/java/com/sendgrid/helpers/mail/Mail.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,28 @@ public class Mail {
SORTED_MAPPER.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
}

private <T> List<T> addToList(T element, List<T> defaultList) {
if (defaultList != null) {
defaultList.add(element);
return defaultList;
} else {
List<T> list = new ArrayList<T>();
list.add(element);
return list;
}
}

private <K,V> Map<K,V> addToMap(K key, V value, Map<K,V> defaultMap) {
if (defaultMap != null) {
defaultMap.put(key, value);
return defaultMap;
} else {
Map<K,V> map = new HashMap<K,V>();
map.put(key, value);
return map;
}
}

/** Construct a new Mail object. */
public Mail() {
return;
Expand Down Expand Up @@ -470,25 +492,73 @@ public String buildPretty() throws IOException {
}
}

private <T> List<T> addToList(T element, List<T> defaultList) {
if (defaultList != null) {
defaultList.add(element);
return defaultList;
} else {
List<T> list = new ArrayList<T>();
list.add(element);
return list;
}
}

private <K,V> Map<K,V> addToMap(K key, V value, Map<K,V> defaultMap) {
if (defaultMap != null) {
defaultMap.put(key, value);
return defaultMap;
} else {
Map<K,V> map = new HashMap<K,V>();
map.put(key, value);
return map;
}
}
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((batchId == null) ? 0 : batchId.hashCode());
result = prime * result + ((categories == null) ? 0 : categories.hashCode());
result = prime * result + ((customArgs == null) ? 0 : customArgs.hashCode());
result = prime * result + ((headers == null) ? 0 : headers.hashCode());
result = prime * result + ((ipPoolId == null) ? 0 : ipPoolId.hashCode());
result = prime * result + ((sections == null) ? 0 : sections.hashCode());
result = prime * result + (int) (sendAt ^ (sendAt >>> 32));
result = prime * result + ((subject == null) ? 0 : subject.hashCode());
result = prime * result + ((templateId == null) ? 0 : templateId.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Mail other = (Mail) obj;
if (batchId == null) {
if (other.batchId != null)
return false;
} else if (!batchId.equals(other.batchId))
return false;
if (categories == null) {
if (other.categories != null)
return false;
} else if (!categories.equals(other.categories))
return false;
if (customArgs == null) {
if (other.customArgs != null)
return false;
} else if (!customArgs.equals(other.customArgs))
return false;
if (headers == null) {
if (other.headers != null)
return false;
} else if (!headers.equals(other.headers))
return false;
if (ipPoolId == null) {
if (other.ipPoolId != null)
return false;
} else if (!ipPoolId.equals(other.ipPoolId))
return false;
if (sections == null) {
if (other.sections != null)
return false;
} else if (!sections.equals(other.sections))
return false;
if (sendAt != other.sendAt)
return false;
if (subject == null) {
if (other.subject != null)
return false;
} else if (!subject.equals(other.subject))
return false;
if (templateId == null) {
if (other.templateId != null)
return false;
} else if (!templateId.equals(other.templateId))
return false;
return true;
}
}
58 changes: 30 additions & 28 deletions src/main/java/com/sendgrid/helpers/mail/objects/ASM.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,51 @@

import java.util.Arrays;

/**
* An object allowing you to specify how to handle unsubscribes.
*/
@JsonInclude(Include.NON_DEFAULT)
public class ASM {

/** The group ID. */
@JsonProperty("group_id") private int groupId;

/** The groups to display property. */
@JsonProperty("groups_to_display") private int[] groupsToDisplay;

/**
* Get the group ID.
* @return the group ID.
*/

@JsonProperty("group_id")
public int getGroupId() {
return groupId;
}

/**
* Set the group ID.
* @param groupId the group ID.
*/

public void setGroupId(int groupId) {
this.groupId = groupId;
}

/**
* Get the groups to display.
* @return the groups to display.
*/

@JsonProperty("groups_to_display")
public int[] getGroupsToDisplay() {
return groupsToDisplay;
}

/**
* Set the groups to display.
* @param groupsToDisplay the groups to display.
*/

public void setGroupsToDisplay(int[] groupsToDisplay) {
this.groupsToDisplay = Arrays.copyOf(groupsToDisplay, groupsToDisplay.length);
}
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + groupId;
result = prime * result + Arrays.hashCode(groupsToDisplay);
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ASM other = (ASM) obj;
if (groupId != other.groupId)
return false;
if (!Arrays.equals(groupsToDisplay, other.groupsToDisplay))
return false;
return true;
}
}
49 changes: 49 additions & 0 deletions src/main/java/com/sendgrid/helpers/mail/objects/Attachments.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,53 @@ public Attachments build() {
return attachments;
}
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((content == null) ? 0 : content.hashCode());
result = prime * result + ((contentId == null) ? 0 : contentId.hashCode());
result = prime * result + ((disposition == null) ? 0 : disposition.hashCode());
result = prime * result + ((filename == null) ? 0 : filename.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Attachments other = (Attachments) obj;
if (content == null) {
if (other.content != null)
return false;
} else if (!content.equals(other.content))
return false;
if (contentId == null) {
if (other.contentId != null)
return false;
} else if (!contentId.equals(other.contentId))
return false;
if (disposition == null) {
if (other.disposition != null)
return false;
} else if (!disposition.equals(other.disposition))
return false;
if (filename == null) {
if (other.filename != null)
return false;
} else if (!filename.equals(other.filename))
return false;
if (type == null) {
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false;
return true;
}
}
46 changes: 29 additions & 17 deletions src/main/java/com/sendgrid/helpers/mail/objects/BccSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,49 @@ public class BccSettings {
@JsonProperty("enable") private boolean enable;
@JsonProperty("email") private String email;

/**
* Determines if this setting is enabled.
* @return true if BCC is enabled, false otherwise.
*/
@JsonProperty("enable")
public boolean getEnable() {
return enable;
}

/**
* Set whether or not BCC is enabled.
* @param enable true if BCC is enabled, false otherwise.
*/
public void setEnable(boolean enable) {
this.enable = enable;
}

/**
* Get the email address that you would like to receive the BCC.
* @return the address.
*/
@JsonProperty("email")
public String getEmail() {
return this.email;
}

/**
* Set the email address that you would like to receive the BCC.
* @param email the address.
*/
public void setEmail(String email) {
this.email = email;
}
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((email == null) ? 0 : email.hashCode());
result = prime * result + (enable ? 1231 : 1237);
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
BccSettings other = (BccSettings) obj;
if (email == null) {
if (other.email != null)
return false;
} else if (!email.equals(other.email))
return false;
if (enable != other.enable)
return false;
return true;
}
}
Loading

0 comments on commit 4d58fcb

Please sign in to comment.