Skip to content

Commit 5600c60

Browse files
authored
Fix unable to remove event participants once set (#83)
The participants list was defaulted to null, which meant when attempting to serialize the object, the value is discarded. Now the default is an empty list, so if the user empties the list of participants, the object will serialize that field to an empty list.
1 parent d8ee0c8 commit 5600c60

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ This section contains changes that have been committed but not yet released.
1414

1515
### Fixed
1616

17+
* Fixed issue where `Event` participants could never be entirely removed once set
18+
1719
### Removed
1820

1921
### Security

src/main/java/com/nylas/Event.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,13 @@ public void addMetadata(String key, String value) {
253253
this.metadata.put(key, value);
254254
}
255255

256+
/**
257+
* Remove all metadata from the event
258+
*/
259+
public void clearMetadata() {
260+
this.metadata.clear();
261+
}
262+
256263
/**
257264
* Add one (or many) notifications to the event
258265
* @param notifications The notification(s) to append to the event's notification list
@@ -264,6 +271,13 @@ public void addNotification(Notification... notifications) {
264271
this.notifications.addAll(Arrays.asList(notifications));
265272
}
266273

274+
/**
275+
* Remove all notifications from the event
276+
*/
277+
public void clearNotifications() {
278+
this.notifications.clear();
279+
}
280+
267281
/**
268282
* Add one (or many) participants to the event
269283
* @param participants The participant(s) to append to the event's participant list
@@ -272,6 +286,13 @@ public void addParticipants(Participant... participants) {
272286
this.participants.addAll(Arrays.asList(participants));
273287
}
274288

289+
/**
290+
* Remove all participants from the event
291+
*/
292+
public void clearParticipants() {
293+
this.participants.clear();
294+
}
295+
275296
/**
276297
* Checks the validity of the event
277298
* @return If the event is valid
@@ -300,7 +321,7 @@ protected Map<String, Object> getWritableFields(boolean creation) {
300321
}
301322
}
302323

303-
List<Map<String, Object>> participantWritableFields = null;
324+
List<Map<String, Object>> participantWritableFields = Collections.emptyList();
304325
if(participants != null && !participants.isEmpty()) {
305326
participantWritableFields = participants.stream()
306327
.map(participant -> participant.getWritableFields(creation))

0 commit comments

Comments
 (0)