From 9a50ad8dea5e9ebc5eb1c5efb19aa7a784283e14 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 16 Jan 2016 18:25:11 +0300 Subject: date and tests --- src/main/java/com/juick/json/MessageSerializer.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/main/java/com/juick') 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 { + + 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 { 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 { 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 { json.put("photo", photo); } } catch (JSONException e) { + LOGGER.log(Level.SEVERE, "JSON Exception", e); } return json; -- cgit v1.2.3