diff options
Diffstat (limited to 'src/main/java/com/juick/json')
-rw-r--r-- | src/main/java/com/juick/json/MessageSerializer.java | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/main/java/com/juick/json/MessageSerializer.java b/src/main/java/com/juick/json/MessageSerializer.java index dccf1b3a..da87d4be 100644 --- a/src/main/java/com/juick/json/MessageSerializer.java +++ b/src/main/java/com/juick/json/MessageSerializer.java @@ -22,6 +22,9 @@ import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; +import java.util.logging.Level; +import java.util.logging.Logger; + import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -31,10 +34,14 @@ import org.json.JSONObject; * @author Ugnich Anton */ public class MessageSerializer extends JSONSerializer<Message> { + + private final static Logger LOGGER = Logger.getLogger(MessageSerializer.class.getName()); UserSerializer userSerializer = new UserSerializer(); PlaceSerializer placeSerializer = new PlaceSerializer(); + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + @Override public Message deserialize(JSONObject json) throws JSONException { com.juick.Message jmsg = new com.juick.Message(); @@ -55,7 +62,7 @@ public class MessageSerializer extends JSONSerializer<Message> { try { DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); df.setTimeZone(TimeZone.getTimeZone("UTC")); - jmsg.Timestamp = df.parse(json.getString("timestamp")); + jmsg.setDate(df.parse(json.getString("timestamp"))); } catch (ParseException e) { } @@ -100,10 +107,8 @@ public class MessageSerializer extends JSONSerializer<Message> { if (msg.getText() != null) { json.put("body", msg.getText()); } - if (msg.Timestamp != null) { - json.put("timestamp", msg.Timestamp); - } else if (msg.TimestampString != null) { - json.put("timestamp", msg.TimestampString); + if (msg.getDate() != null) { + json.put("timestamp", df.format(msg.getDate())); } if (msg.getUser() != null) { json.put("user", userSerializer.serialize(msg.getUser())); @@ -126,6 +131,7 @@ public class MessageSerializer extends JSONSerializer<Message> { json.put("photo", photo); } } catch (JSONException e) { + LOGGER.log(Level.SEVERE, "JSON Exception", e); } return json; |