Skip to content

Commit

Permalink
Refactor Broker Properties Mapper to fix Azure#440
Browse files Browse the repository at this point in the history
  • Loading branch information
justinhughes committed May 25, 2015
1 parent 10c56b2 commit 9c3dfc6
Showing 1 changed file with 11 additions and 6 deletions.
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,9 +47,7 @@ public BrokerProperties fromString(String value) {

public String toString(BrokerProperties 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());
Writer writer = new StringWriter();
try {
mapper.writeValue(writer, value);
Expand All @@ -62,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;
}

}

0 comments on commit 9c3dfc6

Please sign in to comment.