Skip to content

Commit 4d58fcb

Browse files
Merge pull request sendgrid#225 from sccalabr/mailTest
Fixing Mail deserialization issue.
2 parents fe032c9 + 22ba9e9 commit 4d58fcb

17 files changed

+678
-552
lines changed

src/main/java/com/sendgrid/helpers/mail/Mail.java

Lines changed: 92 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,28 @@ public class Mail {
112112
SORTED_MAPPER.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
113113
}
114114

115+
private <T> List<T> addToList(T element, List<T> defaultList) {
116+
if (defaultList != null) {
117+
defaultList.add(element);
118+
return defaultList;
119+
} else {
120+
List<T> list = new ArrayList<T>();
121+
list.add(element);
122+
return list;
123+
}
124+
}
125+
126+
private <K,V> Map<K,V> addToMap(K key, V value, Map<K,V> defaultMap) {
127+
if (defaultMap != null) {
128+
defaultMap.put(key, value);
129+
return defaultMap;
130+
} else {
131+
Map<K,V> map = new HashMap<K,V>();
132+
map.put(key, value);
133+
return map;
134+
}
135+
}
136+
115137
/** Construct a new Mail object. */
116138
public Mail() {
117139
return;
@@ -470,25 +492,73 @@ public String buildPretty() throws IOException {
470492
}
471493
}
472494

473-
private <T> List<T> addToList(T element, List<T> defaultList) {
474-
if (defaultList != null) {
475-
defaultList.add(element);
476-
return defaultList;
477-
} else {
478-
List<T> list = new ArrayList<T>();
479-
list.add(element);
480-
return list;
481-
}
482-
}
483-
484-
private <K,V> Map<K,V> addToMap(K key, V value, Map<K,V> defaultMap) {
485-
if (defaultMap != null) {
486-
defaultMap.put(key, value);
487-
return defaultMap;
488-
} else {
489-
Map<K,V> map = new HashMap<K,V>();
490-
map.put(key, value);
491-
return map;
492-
}
493-
}
494-
}
495+
@Override
496+
public int hashCode() {
497+
final int prime = 31;
498+
int result = 1;
499+
result = prime * result + ((batchId == null) ? 0 : batchId.hashCode());
500+
result = prime * result + ((categories == null) ? 0 : categories.hashCode());
501+
result = prime * result + ((customArgs == null) ? 0 : customArgs.hashCode());
502+
result = prime * result + ((headers == null) ? 0 : headers.hashCode());
503+
result = prime * result + ((ipPoolId == null) ? 0 : ipPoolId.hashCode());
504+
result = prime * result + ((sections == null) ? 0 : sections.hashCode());
505+
result = prime * result + (int) (sendAt ^ (sendAt >>> 32));
506+
result = prime * result + ((subject == null) ? 0 : subject.hashCode());
507+
result = prime * result + ((templateId == null) ? 0 : templateId.hashCode());
508+
return result;
509+
}
510+
511+
@Override
512+
public boolean equals(Object obj) {
513+
if (this == obj)
514+
return true;
515+
if (obj == null)
516+
return false;
517+
if (getClass() != obj.getClass())
518+
return false;
519+
Mail other = (Mail) obj;
520+
if (batchId == null) {
521+
if (other.batchId != null)
522+
return false;
523+
} else if (!batchId.equals(other.batchId))
524+
return false;
525+
if (categories == null) {
526+
if (other.categories != null)
527+
return false;
528+
} else if (!categories.equals(other.categories))
529+
return false;
530+
if (customArgs == null) {
531+
if (other.customArgs != null)
532+
return false;
533+
} else if (!customArgs.equals(other.customArgs))
534+
return false;
535+
if (headers == null) {
536+
if (other.headers != null)
537+
return false;
538+
} else if (!headers.equals(other.headers))
539+
return false;
540+
if (ipPoolId == null) {
541+
if (other.ipPoolId != null)
542+
return false;
543+
} else if (!ipPoolId.equals(other.ipPoolId))
544+
return false;
545+
if (sections == null) {
546+
if (other.sections != null)
547+
return false;
548+
} else if (!sections.equals(other.sections))
549+
return false;
550+
if (sendAt != other.sendAt)
551+
return false;
552+
if (subject == null) {
553+
if (other.subject != null)
554+
return false;
555+
} else if (!subject.equals(other.subject))
556+
return false;
557+
if (templateId == null) {
558+
if (other.templateId != null)
559+
return false;
560+
} else if (!templateId.equals(other.templateId))
561+
return false;
562+
return true;
563+
}
564+
}

src/main/java/com/sendgrid/helpers/mail/objects/ASM.java

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,51 @@
66

77
import java.util.Arrays;
88

9-
/**
10-
* An object allowing you to specify how to handle unsubscribes.
11-
*/
129
@JsonInclude(Include.NON_DEFAULT)
1310
public class ASM {
14-
15-
/** The group ID. */
1611
@JsonProperty("group_id") private int groupId;
17-
18-
/** The groups to display property. */
1912
@JsonProperty("groups_to_display") private int[] groupsToDisplay;
20-
21-
/**
22-
* Get the group ID.
23-
* @return the group ID.
24-
*/
13+
2514
@JsonProperty("group_id")
2615
public int getGroupId() {
2716
return groupId;
2817
}
29-
30-
/**
31-
* Set the group ID.
32-
* @param groupId the group ID.
33-
*/
18+
3419
public void setGroupId(int groupId) {
3520
this.groupId = groupId;
3621
}
37-
38-
/**
39-
* Get the groups to display.
40-
* @return the groups to display.
41-
*/
22+
4223
@JsonProperty("groups_to_display")
4324
public int[] getGroupsToDisplay() {
4425
return groupsToDisplay;
4526
}
46-
47-
/**
48-
* Set the groups to display.
49-
* @param groupsToDisplay the groups to display.
50-
*/
27+
5128
public void setGroupsToDisplay(int[] groupsToDisplay) {
5229
this.groupsToDisplay = Arrays.copyOf(groupsToDisplay, groupsToDisplay.length);
5330
}
54-
}
31+
32+
@Override
33+
public int hashCode() {
34+
final int prime = 31;
35+
int result = 1;
36+
result = prime * result + groupId;
37+
result = prime * result + Arrays.hashCode(groupsToDisplay);
38+
return result;
39+
}
40+
41+
@Override
42+
public boolean equals(Object obj) {
43+
if (this == obj)
44+
return true;
45+
if (obj == null)
46+
return false;
47+
if (getClass() != obj.getClass())
48+
return false;
49+
ASM other = (ASM) obj;
50+
if (groupId != other.groupId)
51+
return false;
52+
if (!Arrays.equals(groupsToDisplay, other.groupsToDisplay))
53+
return false;
54+
return true;
55+
}
56+
}

src/main/java/com/sendgrid/helpers/mail/objects/Attachments.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,53 @@ public Attachments build() {
238238
return attachments;
239239
}
240240
}
241+
242+
@Override
243+
public int hashCode() {
244+
final int prime = 31;
245+
int result = 1;
246+
result = prime * result + ((content == null) ? 0 : content.hashCode());
247+
result = prime * result + ((contentId == null) ? 0 : contentId.hashCode());
248+
result = prime * result + ((disposition == null) ? 0 : disposition.hashCode());
249+
result = prime * result + ((filename == null) ? 0 : filename.hashCode());
250+
result = prime * result + ((type == null) ? 0 : type.hashCode());
251+
return result;
252+
}
253+
254+
@Override
255+
public boolean equals(Object obj) {
256+
if (this == obj)
257+
return true;
258+
if (obj == null)
259+
return false;
260+
if (getClass() != obj.getClass())
261+
return false;
262+
Attachments other = (Attachments) obj;
263+
if (content == null) {
264+
if (other.content != null)
265+
return false;
266+
} else if (!content.equals(other.content))
267+
return false;
268+
if (contentId == null) {
269+
if (other.contentId != null)
270+
return false;
271+
} else if (!contentId.equals(other.contentId))
272+
return false;
273+
if (disposition == null) {
274+
if (other.disposition != null)
275+
return false;
276+
} else if (!disposition.equals(other.disposition))
277+
return false;
278+
if (filename == null) {
279+
if (other.filename != null)
280+
return false;
281+
} else if (!filename.equals(other.filename))
282+
return false;
283+
if (type == null) {
284+
if (other.type != null)
285+
return false;
286+
} else if (!type.equals(other.type))
287+
return false;
288+
return true;
289+
}
241290
}

src/main/java/com/sendgrid/helpers/mail/objects/BccSettings.java

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,49 @@ public class BccSettings {
1414
@JsonProperty("enable") private boolean enable;
1515
@JsonProperty("email") private String email;
1616

17-
/**
18-
* Determines if this setting is enabled.
19-
* @return true if BCC is enabled, false otherwise.
20-
*/
2117
@JsonProperty("enable")
2218
public boolean getEnable() {
2319
return enable;
2420
}
2521

26-
/**
27-
* Set whether or not BCC is enabled.
28-
* @param enable true if BCC is enabled, false otherwise.
29-
*/
3022
public void setEnable(boolean enable) {
3123
this.enable = enable;
3224
}
3325

34-
/**
35-
* Get the email address that you would like to receive the BCC.
36-
* @return the address.
37-
*/
3826
@JsonProperty("email")
3927
public String getEmail() {
4028
return this.email;
4129
}
4230

43-
/**
44-
* Set the email address that you would like to receive the BCC.
45-
* @param email the address.
46-
*/
4731
public void setEmail(String email) {
4832
this.email = email;
4933
}
50-
}
34+
35+
@Override
36+
public int hashCode() {
37+
final int prime = 31;
38+
int result = 1;
39+
result = prime * result + ((email == null) ? 0 : email.hashCode());
40+
result = prime * result + (enable ? 1231 : 1237);
41+
return result;
42+
}
43+
44+
@Override
45+
public boolean equals(Object obj) {
46+
if (this == obj)
47+
return true;
48+
if (obj == null)
49+
return false;
50+
if (getClass() != obj.getClass())
51+
return false;
52+
BccSettings other = (BccSettings) obj;
53+
if (email == null) {
54+
if (other.email != null)
55+
return false;
56+
} else if (!email.equals(other.email))
57+
return false;
58+
if (enable != other.enable)
59+
return false;
60+
return true;
61+
}
62+
}

0 commit comments

Comments
 (0)