From 51d9de02265d6cc9d6045d79497d2a987ae2f7f7 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 15 Nov 2016 14:21:27 +0300 Subject: core classes are now serializeable with JAXB (to use as babbler extension) --- .../java/com/juick/json/MessageSerializer.java | 26 +++++++++++----------- .../main/java/com/juick/json/UserSerializer.java | 12 +++++----- 2 files changed, 19 insertions(+), 19 deletions(-) (limited to 'juick-core/src/main/java/com/juick/json') diff --git a/juick-core/src/main/java/com/juick/json/MessageSerializer.java b/juick-core/src/main/java/com/juick/json/MessageSerializer.java index 3ef903f0..ebc3b0b0 100644 --- a/juick-core/src/main/java/com/juick/json/MessageSerializer.java +++ b/juick-core/src/main/java/com/juick/json/MessageSerializer.java @@ -51,12 +51,12 @@ public class MessageSerializer extends JSONSerializer { @Override public Message deserialize(JSONObject json) throws JSONException, ParseException { com.juick.Message jmsg = new com.juick.Message(); - jmsg.setMID(json.getInt("mid")); + jmsg.setMid(json.getInt("mid")); if (json.has("rid")) { - jmsg.setRID(json.getInt("rid")); + jmsg.setRid(json.getInt("rid")); } if (json.has("replyto")) { - jmsg.ReplyTo = json.getInt("replyto"); + jmsg.setReplyto(json.getInt("replyto")); } jmsg.FriendsOnly = json.has("friendsonly"); @@ -70,7 +70,7 @@ public class MessageSerializer extends JSONSerializer { if (json.has("tags")) { JSONArray tags = json.getJSONArray("tags"); for (int n = 0; n < tags.length(); n++) { - jmsg.Tags.add(new Tag(tags.getString(n).replace(""", "\""))); + jmsg.getTags().add(new Tag(tags.getString(n).replace(""", "\""))); } } @@ -90,14 +90,14 @@ public class MessageSerializer extends JSONSerializer { JSONObject json = new JSONObject(); try { - if (msg.getMID() > 0) { - json.put("mid", msg.getMID()); + if (msg.getMid() > 0) { + json.put("mid", msg.getMid()); } - if (msg.getRID() > 0) { - json.put("rid", msg.getRID()); + if (msg.getRid() > 0) { + json.put("rid", msg.getRid()); } - if (msg.ReplyTo > 0) { - json.put("replyto", msg.ReplyTo); + if (msg.getReplyto() > 0) { + json.put("replyto", msg.getReplyto()); } if (msg.FriendsOnly) { json.put("friendsonly", 1); @@ -114,8 +114,8 @@ public class MessageSerializer extends JSONSerializer { if (msg.getUser() != null) { json.put("user", userSerializer.serialize(msg.getUser())); } - if (msg.Tags != null && msg.Tags.size() > 0) { - json.put("tags", new JSONArray(msg.Tags.stream().map(Tag::getName).collect(Collectors.toList()))); + if (msg.getTags() != null && msg.getTags().size() > 0) { + json.put("tags", new JSONArray(msg.getTags().stream().map(Tag::getName).collect(Collectors.toList()))); } if (msg.Replies > 0) { json.put("replies", msg.Replies); @@ -124,7 +124,7 @@ public class MessageSerializer extends JSONSerializer { json.put("place", placeSerializer.serialize(msg.Place)); } if (msg.AttachmentType != null) { - String fname = msg.getMID() + (msg.getRID() > 0 ? "-" + msg.getRID() : "") + "." + msg.AttachmentType; + String fname = msg.getMid() + (msg.getRid() > 0 ? "-" + msg.getRid() : "") + "." + msg.AttachmentType; JSONObject photo = new JSONObject(); String protocol = getUriScheme() == URIScheme.Plain ? "http:" : "https:"; photo.put("thumbnail", protocol + "//i.juick.com/ps/" + fname); diff --git a/juick-core/src/main/java/com/juick/json/UserSerializer.java b/juick-core/src/main/java/com/juick/json/UserSerializer.java index 390f4bf6..08d21d39 100644 --- a/juick-core/src/main/java/com/juick/json/UserSerializer.java +++ b/juick-core/src/main/java/com/juick/json/UserSerializer.java @@ -30,8 +30,8 @@ public class UserSerializer extends JSONSerializer { @Override public User deserialize(JSONObject json) throws JSONException { User juser = new User(); - juser.setUID(json.getInt("uid")); - juser.setUName(json.getString("uname")); + juser.setUid(json.getInt("uid")); + juser.setName(json.getString("uname")); if (json.has("fullname")) { juser.setFullName(json.getString("fullname")); } @@ -43,11 +43,11 @@ public class UserSerializer extends JSONSerializer { JSONObject json = new JSONObject(); try { - if (user.getUID() > 0) { - json.put("uid", user.getUID()); + if (user.getUid() > 0) { + json.put("uid", user.getUid()); } - if (user.getUName() != null) { - json.put("uname", user.getUName()); + if (user.getName() != null) { + json.put("uname", user.getName()); } if (user.getFullName() != null) { json.put("fullname", user.getFullName()); -- cgit v1.2.3