Skip to content

Commit 271a776

Browse files
authored
Merge pull request #21 from messagebird/date-format-bug
Explicitly set the date format before sending POST requests
2 parents 5a2a7c4 + 1fe3232 commit 271a776

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

api/src/main/java/com/messagebird/MessageBirdServiceImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import java.net.Proxy;
88
import java.net.URL;
99
import java.net.URLEncoder;
10+
import java.text.DateFormat;
11+
import java.text.SimpleDateFormat;
1012
import java.util.Arrays;
1113
import java.util.LinkedHashMap;
1214
import java.util.List;
@@ -191,6 +193,12 @@ public <P> HttpURLConnection getConnection(final String serviceUrl, final P post
191193
ObjectMapper mapper = new ObjectMapper();
192194
mapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
193195

196+
// Specifically set the date format for POST requests so scheduled
197+
// messages and other things relying on specific date formats don't
198+
// fail when sending.
199+
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZ");
200+
mapper.setDateFormat(df);
201+
194202
final String json = mapper.writeValueAsString(postData);
195203
connection.getOutputStream().write(json.getBytes("UTF-8"));
196204
} else if ("DELETE".equals(requestType)) {

0 commit comments

Comments
 (0)