aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/json/JSONSerializer.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2015-11-04 15:24:53 +0300
committerGravatar Vitaly Takmazov2015-11-04 15:25:35 +0300
commit655b821e274ca4be078389475a8bb33139c55a4f (patch)
tree6319c4ba8c32bff6e1f4116665ac90b75468d0ad /src/main/java/com/juick/json/JSONSerializer.java
parent5f4602b34ccc3f899edd45e5e541cbb7307c9585 (diff)
refactoring
Diffstat (limited to 'src/main/java/com/juick/json/JSONSerializer.java')
-rw-r--r--src/main/java/com/juick/json/JSONSerializer.java53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/main/java/com/juick/json/JSONSerializer.java b/src/main/java/com/juick/json/JSONSerializer.java
new file mode 100644
index 00000000..8ac72cb0
--- /dev/null
+++ b/src/main/java/com/juick/json/JSONSerializer.java
@@ -0,0 +1,53 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package com.juick.json;
+
+import java.util.Iterator;
+import java.util.List;
+import org.json.JSONObject;
+
+/**
+ *
+ * @author vt
+ * @param <T>
+ */
+public abstract class JSONSerializer<T> {
+
+ /**
+ *
+ * @param json
+ * @return
+ */
+ public abstract T deserialize(JSONObject json);
+
+ /**
+ *
+ * @param obj
+ * @return
+ */
+ public abstract JSONObject serialize(T obj);
+
+ /**
+ *
+ * @param objs
+ * @return
+ */
+ public String serializeList(List<T> objs) {
+ String json = "[";
+
+ Iterator<T> i = objs.iterator();
+ while (i.hasNext()) {
+ T m = i.next();
+ if (json.length() > 1) {
+ json += ",";
+ }
+ json += serialize(m).toString();
+ }
+
+ json += "]";
+ return json;
+ }
+}