Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#440 (Service Bus) - Fix Serialization Of Dates #476

Merged
merged 3 commits into from
Jan 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.TimeZone;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.JsonParseException;
Expand All @@ -30,9 +32,7 @@ public class BrokerPropertiesMapper {
public BrokerProperties fromString(String value) {

ObjectMapper mapper = new ObjectMapper();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
"EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
mapper.setDateFormat(simpleDateFormat);
mapper.setDateFormat(getRFC2616DateFormatter());
try {
return mapper.readValue(value.getBytes("UTF-8"),
BrokerProperties.class);
Expand All @@ -47,6 +47,7 @@ public BrokerProperties fromString(String value) {

public String toString(BrokerProperties value) {
ObjectMapper mapper = new ObjectMapper();
mapper.setDateFormat(getRFC2616DateFormatter());
Writer writer = new StringWriter();
try {
mapper.writeValue(writer, value);
Expand All @@ -59,5 +60,12 @@ public String toString(BrokerProperties value) {
}
return writer.toString();
}

private DateFormat getRFC2616DateFormatter() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
"EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
return simpleDateFormat;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,21 @@ public void deserializeDateInZhCnLocaleCorrectly() {
- lockedUntilUtc.getTime();
assertTrue(Math.abs(lockedUntilDelta) < 2000);
}

@Test
public void dateSerializeCorrectlyToRFC2616() {
// Arrange
BrokerPropertiesMapper mapper = new BrokerPropertiesMapper();
Date date = new Date(1432120118000L);

// Act
BrokerProperties properties = new BrokerProperties();
properties.setScheduledEnqueueTimeUtc(date);
String json = mapper.toString(properties);

// Assert
assertNotNull(json);
assertEquals("{\"ScheduledEnqueueTimeUtc\":\"Wed, 20 May 2015 11:08:38 GMT\"}", json);

}
}