From 63b14e7818a20d598e4634a0ee686376d7f687b2 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 4 Nov 2015 15:18:41 +0300 Subject: drop gson, refactoring --- src/main/java/com/juick/api/Messages.java | 7 +++++-- src/main/java/com/juick/api/Others.java | 5 ++++- src/main/java/com/juick/api/PM.java | 7 +++++-- src/main/java/com/juick/api/Users.java | 9 ++++++--- 4 files changed, 20 insertions(+), 8 deletions(-) (limited to 'src/main/java/com/juick/api') diff --git a/src/main/java/com/juick/api/Messages.java b/src/main/java/com/juick/api/Messages.java index b7a55361..548e816f 100644 --- a/src/main/java/com/juick/api/Messages.java +++ b/src/main/java/com/juick/api/Messages.java @@ -1,5 +1,6 @@ package com.juick.api; +import com.juick.json.MessageSerializer; import com.juick.server.MessagesQueries; import com.juick.xmpp.JID; import com.juick.xmpp.Message; @@ -19,6 +20,8 @@ import javax.servlet.http.HttpServletResponse; public class Messages { Connection sql; + + MessageSerializer messageSerializer = new MessageSerializer(); public Messages(Connection sql) { this.sql = sql; @@ -31,7 +34,7 @@ public class Messages { if (mids != null && !mids.isEmpty()) { ArrayList msgs = MessagesQueries.getMessages(sql, mids); if (msgs != null && !msgs.isEmpty()) { - String json = com.juick.json.Messages.arrayToString(msgs); + String json = messageSerializer.serializeList(msgs); Main.replyJSON(request, response, json); } else { response.sendError(404); @@ -48,7 +51,7 @@ public class Messages { if (mids != null && !mids.isEmpty()) { ArrayList msgs = MessagesQueries.getMessages(sql, mids); if (msgs != null && !msgs.isEmpty()) { - String json = com.juick.json.Messages.arrayToString(msgs); + String json = messageSerializer.serializeList(msgs); Main.replyJSON(request, response, json); } else { response.sendError(404); diff --git a/src/main/java/com/juick/api/Others.java b/src/main/java/com/juick/api/Others.java index 25df5bf4..5e5c7475 100644 --- a/src/main/java/com/juick/api/Others.java +++ b/src/main/java/com/juick/api/Others.java @@ -1,5 +1,6 @@ package com.juick.api; +import com.juick.json.UserSerializer; import com.juick.server.PMQueries; import java.io.IOException; import java.sql.Connection; @@ -15,6 +16,8 @@ import javax.servlet.http.HttpServletResponse; public class Others { Connection sql; + + UserSerializer userSerializer = new UserSerializer(); public Others(Connection sql) { this.sql = sql; @@ -36,7 +39,7 @@ public class Others { ArrayList lastconv = PMQueries.getPMLastConversationsUsers(sql, vuid, cnt); if (lastconv != null && !lastconv.isEmpty()) { - String json = "{\"pms\":" + com.juick.json.Users.arrayToString(lastconv) + "}"; + String json = "{\"pms\":" + userSerializer.serializeList(lastconv) + "}"; Main.replyJSON(request, response, json); } else { response.sendError(404); diff --git a/src/main/java/com/juick/api/PM.java b/src/main/java/com/juick/api/PM.java index 2722526d..ffcd155a 100644 --- a/src/main/java/com/juick/api/PM.java +++ b/src/main/java/com/juick/api/PM.java @@ -1,5 +1,6 @@ package com.juick.api; +import com.juick.json.MessageSerializer; import com.juick.server.PMQueries; import com.juick.server.UserQueries; import com.juick.xmpp.JID; @@ -20,6 +21,8 @@ import javax.servlet.http.HttpServletResponse; public class PM { Connection sql; + + MessageSerializer messageSerializer = new MessageSerializer(); public PM(Connection sql) { this.sql = sql; @@ -39,7 +42,7 @@ public class PM { ArrayList msgs = PMQueries.getPMMessages(sql, vuid, uid); if (msgs != null && !msgs.isEmpty()) { - String json = com.juick.json.Messages.arrayToString(msgs); + String json = messageSerializer.serializeList(msgs); Main.replyJSON(request, response, json); } else { response.sendError(404); @@ -77,7 +80,7 @@ public class PM { msg.to.Host = "ws.juick.com"; xmpp.send(msg); - Main.replyJSON(request, response, com.juick.json.Message.toJSON(jmsg).toString()); + Main.replyJSON(request, response, messageSerializer.serialize(jmsg).toString()); String jid = UserQueries.getJIDbyUID(sql, uid); if (jid != null) { diff --git a/src/main/java/com/juick/api/Users.java b/src/main/java/com/juick/api/Users.java index cdd48fd6..37c9ca49 100644 --- a/src/main/java/com/juick/api/Users.java +++ b/src/main/java/com/juick/api/Users.java @@ -1,6 +1,7 @@ package com.juick.api; import com.juick.User; +import com.juick.json.UserSerializer; import com.juick.server.UserQueries; import java.io.IOException; import java.sql.Connection; @@ -18,6 +19,8 @@ import javax.servlet.http.HttpServletResponse; public class Users { Connection sql; + + UserSerializer userSerializer = new UserSerializer(); public Users(Connection sql) { this.sql = sql; @@ -55,7 +58,7 @@ public class Users { } if (!users.isEmpty()) { - String json = com.juick.json.Users.arrayToString(users); + String json = userSerializer.serializeList(users); Main.replyJSON(request, response, json); } else { response.sendError(404); @@ -81,7 +84,7 @@ public class Users { if (uids.size() > 0) { ArrayList users = UserQueries.getUsersByID(sql, uids); if (users.size() > 0) { - String json = com.juick.json.Users.arrayToString(users); + String json = userSerializer.serializeList(users); Main.replyJSON(request, response, json); return; } @@ -109,7 +112,7 @@ public class Users { if (uids.size() > 0) { ArrayList users = UserQueries.getUsersByID(sql, uids); if (users.size() > 0) { - String json = com.juick.json.Users.arrayToString(users); + String json = userSerializer.serializeList(users); Main.replyJSON(request, response, json); return; } -- cgit v1.2.3