From 143513cec90ab176e5c174fb4ed98c249652bda6 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 16 Jan 2016 19:13:30 +0300 Subject: refactoring --- src/main/java/com/juick/json/JSONSerializer.java | 3 ++- src/main/java/com/juick/json/MessageSerializer.java | 16 ++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) (limited to 'src/main/java/com') diff --git a/src/main/java/com/juick/json/JSONSerializer.java b/src/main/java/com/juick/json/JSONSerializer.java index 8ac72cb0..142cacf0 100644 --- a/src/main/java/com/juick/json/JSONSerializer.java +++ b/src/main/java/com/juick/json/JSONSerializer.java @@ -5,6 +5,7 @@ */ package com.juick.json; +import java.text.ParseException; import java.util.Iterator; import java.util.List; import org.json.JSONObject; @@ -21,7 +22,7 @@ public abstract class JSONSerializer { * @param json * @return */ - public abstract T deserialize(JSONObject json); + public abstract T deserialize(JSONObject json) throws ParseException; /** * diff --git a/src/main/java/com/juick/json/MessageSerializer.java b/src/main/java/com/juick/json/MessageSerializer.java index da87d4be..4818722f 100644 --- a/src/main/java/com/juick/json/MessageSerializer.java +++ b/src/main/java/com/juick/json/MessageSerializer.java @@ -40,10 +40,15 @@ public class MessageSerializer extends JSONSerializer { UserSerializer userSerializer = new UserSerializer(); PlaceSerializer placeSerializer = new PlaceSerializer(); - SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + final SimpleDateFormat df; + + public MessageSerializer() { + df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + df.setTimeZone(TimeZone.getTimeZone("UTC")); + } @Override - public Message deserialize(JSONObject json) throws JSONException { + public Message deserialize(JSONObject json) throws JSONException, ParseException { com.juick.Message jmsg = new com.juick.Message(); jmsg.setMID(json.getInt("mid")); if (json.has("rid")) { @@ -59,12 +64,7 @@ public class MessageSerializer extends JSONSerializer { jmsg.setText(json.getString("body").replace(""", "\"")); jmsg.setUser(userSerializer.deserialize(json.getJSONObject("user"))); - try { - DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - df.setTimeZone(TimeZone.getTimeZone("UTC")); - jmsg.setDate(df.parse(json.getString("timestamp"))); - } catch (ParseException e) { - } + jmsg.setDate(df.parse(json.getString("timestamp"))); if (json.has("tags")) { JSONArray tags = json.getJSONArray("tags"); -- cgit v1.2.3