Skip to content

Commit

Permalink
Merge pull request #21 from messagebird/date-format-bug
Browse files Browse the repository at this point in the history
Explicitly set the date format before sending POST requests
  • Loading branch information
dysosmus authored Mar 24, 2017
2 parents 5a2a7c4 + 1fe3232 commit 271a776
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.net.Proxy;
import java.net.URL;
import java.net.URLEncoder;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -191,6 +193,12 @@ public <P> HttpURLConnection getConnection(final String serviceUrl, final P post
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);

// Specifically set the date format for POST requests so scheduled
// messages and other things relying on specific date formats don't
// fail when sending.
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZ");
mapper.setDateFormat(df);

final String json = mapper.writeValueAsString(postData);
connection.getOutputStream().write(json.getBytes("UTF-8"));
} else if ("DELETE".equals(requestType)) {
Expand Down

0 comments on commit 271a776

Please sign in to comment.